Advanced 2D Collision det and physics

Started by
1 comment, last by oliii 19 years, 7 months ago
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
Advertisement
Take a look at oliii's website. He has pretty good stuff on collision detection that is worth to be seen.

linky1

EDIT: Also look at his profile. He posted A LOT about the subject.
[size="2"]I like the Walrus best.
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.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement