A Flash Developer Resource Site

# Thread: Ball collision - hitTest based?

1. ## Ball collision - hitTest based?

Do anyone have a code that makes a ball bounce realistic with hitTest(x,y,true)? I would need that, and I've tried to make it for one year now.

2. for the hittest detection in a ball
you must
ps. the point in the ball must be in the center

detect=(floor.hittest(ball._x+ball.width*0.5,ball. _y,true))||(floor.hittest(ball._x-ball.width*0.5,ball._y,true))||(floor.hittest(ball ._y+ball.height*0.5,ball._x,true))||(floor.hittest (ball._y-ball.height*0.5,ball._x,true))

if(detect){
//invert speeds of the ball
}

don`t forget the ball always has a little force going down

3. Not exacly that I meant. I meant ball bouncing like THIS:
http://www.harveycartel.org/metanet/...tB_demo04.html

... based on hitTest. Is it possible?

4. you could use trigonometry instead?

then the balls would be able to bouce off each other correctly and it'd all be contained in the same code.

how are you with trig?

5. i've done a quick demo of collision with trigonometry.

here you go.

to get the collisions or rather the bounces realistic, you'l need to look at the angle ball B is to A, then find the angle ball A's path is (left right, no up/down is 90 degrees) then use some maths to calculate the new angle then from that work out the co ordinate ratios (amount moving x and y) based on a set speed.

i was trying to do it then realised i have my own work to do! lol good luck!

6. Thanks, but that's not what I need. I know how to make ball vs ball collision.
I want to know how I can make this[http://www.harveycartel.org/metanet...utB_demo04.html] with hitTest - ball vs that kind of ground.

7. Ever find a solution to this?

I was thinking of finding the tangent of the colliding surfaces and the angle between them for deflection.

Any ideas on how this can be done?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap