• Create Account

Banner advertising on our site currently available from just \$5!

Vector collision

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

#1stein102  Members   -  Reputation: 515

Like
1Likes
Like

Posted 28 March 2013 - 11:34 PM

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.

#2slicer4ever  Crossbones+   -  Reputation: 4809

Like
1Likes
Like

Posted 29 March 2013 - 04:24 AM

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.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#3stein102  Members   -  Reputation: 515

Like
1Likes
Like

Posted 29 March 2013 - 09:41 PM

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

#4Yrjö P.  Crossbones+   -  Reputation: 1416

Like
0Likes
Like

Posted 31 March 2013 - 05:44 AM

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

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS