Sign in to follow this  

Advanced 2D Collision det and physics

This topic is 4835 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

Hello, Working on a testbed program for another idea of mine, I decided to implement a slightly improvised pong/breakout like clone. I didnt want to limit myself to horizontal and vertical collisions though, so i decided to implement collisions based soley on lines and circles (4 lines in a rect, etc.) then being able to have the lines skewed. I figured this was also a good way to be able to change the collision type based on which part of a shape was hit (defined by the line segment). I am having a few problems with this approch though.. The most massive I have is... how to define a line? In normal computer terms, i would define it as a pair of X&Y values, but doing that in this case does not provide the information to accuratly detect the collision or the bounce, so i figured having a slope, but then that rules out vertical lines (both vertical and horizontal lines will be commonplace enough for that to pose problems. I thought about using an angle value to specify the slope, but im not sure the drawbacks on that approch. I figure if I do have the angle of skew for the line, i could use that angle to turn some sort of 2d vector and figure out the standard bounce angle, then turn the line again. Or something im the sort. I feel that I am confusing myself, if someone would bother pushing me in the right direction here... LOL. Thanks

Share this post


Link to post
Share on other sites
the simnplest way to do that sort of thing is through vector maths. As you said, a segment is defined by two points, and using vector maths, that's all you need. I can't really explain how the thing would work as it might confuse you if you don't know vector maths, but for a quick intro, have a look at

http://www.geocities.com/SiliconValley/2151/math2d.html

http://www.gamedev.net/reference/articles/article1832.asp

http://collective.valve-erc.com/index.php?doc=1039880877-82189500

some of them are in 3D, but 2D is the same (except maybe for the cross product).

from there, once you're cool manipulating vectors, it's pretty straight forward. It's just geometry. No matter what angle you choose for the line, the equations would be very simple, and work always the same.

Share this post


Link to post
Share on other sites

This topic is 4835 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.

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