Sign in to follow this  
stein102

Vector collision

Recommended Posts

Can anyone suggest a good article or tutorial on how to implement vector based collisions/movement in a game? Right now my game is just set up with simple x and y coordinates and dx/dy variables that represent the speed in both the x and y components of the game. If it helps anyone explain it a little better, I'm working on a breakout game and want to get the collision done properly.

Share this post


Link to post
Share on other sites
Basically, you find the plane that your collision is happening on, then you reflect your velocity over that plane: http://www.3dkingdoms.com/weekly/weekly.php?a=2

in essence, for a game that is strictly AABB(Axis-Aligned Bounding Boxes) boxes, you figure out which side of the brick you are colliding with, then negate the appropriate axis, for example, if your hitting the bottom or top of a brick, simply negate the y velocity. same for x when hitting the left/right. just be sure to also push the ball out of the brick/paddle, otherwise you might inadvertently cause the ball to continously flip it's velocity if it somehow ends up inside the brick.

Share this post


Link to post
Share on other sites

What's a good way to find out which side of the brick I'm colliding with?

 

On this previous thread, I wrote an explanation of how to solve the colliding side on a box-box collision exactly:

http://www.gamedev.net/topic/634693-two-rectangles-colliding/#entry5003279

 

If you get stuck on some part of the explanation, feel free to ask. You should probably draw the situation on paper while following the logic.

 

(It's another matter whether a Breakout game is best served by strict rectangle-rectangle collision; ultimately you'd probably want to add a special case for handling corner hits so the ball will bounce off at different angles.)

 

Another approach is to take the angle between velocity vectors and then use that somehow to estimate the type of the hit. This isn't an exact solution and will require hand-tuning for specific rectangle shapes. You get the cosine of the angle by dividing the dot product with vector lengths:

http://en.wikipedia.org/wiki/Dot_product#Algebraic_definition

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