Sign in to follow this  
Adir

Breakout physics

Recommended Posts

I'm trying to build a breakout clone using XNA. My main problem now its the ball collision detection. I know that I need to invert the ball velocity when there is a hit, but how can I know if the ball hit the left/right side of the brick or the top/bottom side? Thanks :)

Share this post


Link to post
Share on other sites
Hi there. Each block is what's known as a AABB (axis aligned bounding box). There are many ways of implementing it, too, and the math isn't that difficult behind it either. Here's some more information on someone who had a similar problem:

http://board.flashkit.com/board/showthread.php?t=773872

and additionaly:

http://www.google.com/search?hl=en&rlz=1G1GGLQ_ENNZ324&q=aabb+circle+collision&aq=f&oq=&aqi=


The thing you will really need to consider when doing this though, is how you can reduce the number of rectangles you need to check against the circle otherwise you may have a performance bottle neck having something like this:


for(every rectangle)
if(collision(rectangle[n], sphere)
// bounce off


"how can I know if the ball hit the left/right side of the brick or the top/bottom side?"

You will want to store the distance from the ball's radius to the point of intersection, then should be able to calculate the normal straight off from there, then you woudln't have to worry about what side it actually hit.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this