2 Replies Latest reply on Sep 12, 2008 3:45 PM by shintashi

# Multiple HitTest Questions

Hi, this is a multiple part question, and hopefully if answered, will be able to help several people with multiple problems in the category of Collision Detection.
My first objective is to have the ability to go from frame 1 to frame 2 when an object controlled with arrow keys makes contact with another object (movie clip OR button, preferably both for different reasons). This seems simple but the hitTest help file only talks about coordinates or "on Release" drag-drop versions, and the tutorials don't appear to favor two moving movie clips colliding.

second, I have sliding floors for a jumping ball/character, but the character when landing on the sliding floor remains stationary, so I need some kind of friction to go with the gravity.

Third, If my jumping ball, or bouncing ball is using a greater than 1.0 restitution (trampoline effect) how do I make a ceiling to collide into?

Finally, is there a way to make gravity go sideways or upside-down to simulate wind, and if possible, can both down gravity and x-axis gravity be used together (aka flight/gliding sim)?
• ###### 1. Re: Multiple HitTest Questions
You have a lot of questions and most of them are fairly complicated -- in the sense of how to make them all work together. I would recommend you get this book:

http://www.amazon.com/Foundation-Actionscript-3-0-Animation-Making/dp/1590597915

Or the AS2 version if you are working in AS2.

1. You can use a setInterval to perform hitTesting or you can use an onEnterFrame handler.

2. Friction is just an acceleration against the direction of motion.

3. You collide with a ceiling the same way you collide with a floor (or wall) by checking for collision or that _y position is less than some value.

4. Well gravity doesn't generally go different directions, but it could. Again it is just a constant acceleration applied in a specific direction. So if you have an x direction velocity you just apply an x direction acceleration for gravity.

• ###### 2. Re: Multiple HitTest Questions
I got the four directions of gravity to work by reversing some of the values and four direction "ground" by fiddling with the boundaries for example:

>>
onClipEvent(enterFrame) {
vel.y += _root.gravity;

pos.x += vel.x;
pos.y += vel.y;

if( pos.y + radius > movie.height ) {
pos.y = movie.height - radius;
vel.y *= -_root.restitution;
}
<<
becomes

>>

onClipEvent(enterFrame) {
vel.y += _root.gravity;

pos.x += vel.x;
pos.y += vel.y;

if( pos.y + radius < 0 ) {
pos.y = 0 + radius;
vel.y *= -_root.restitution;
}
<<

but now im trying to use four buttons linked to an array to switch between frames and it's not working (I'm terrible at arrays)