Jump to content
  • Advertisement
Sign in to follow this  
stein102

Vector collision

This topic is 1999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!