Public Group

# Vector collision

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

## 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 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 on other sites

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

##### 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

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633729
• Total Posts
3013578
×