Wall Collision and Sliding

Started by elias4444, May 11, 2006, 16:40:42

Previous topic - Next topic

elias4444

I haven't been able to find the math for this anywhere else (at least, not in understandable form for Java's purposes). I have objects that are in constant motion (dx and dy are alway greater than or less than 0). When they collide with a "wall" (a line, that starts at sx,sy and ends at ex,ey) I want them to slide along it. Every instance I've found that's similar talks about "bouncing" the object off the wall, but that's not what I'm after. Anyone out there a math/java buff that could help me figure out how to code this?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Sardtok

If the object moves through the line, pull it back to a position along the normal of the line (x=y y=-x or x=-y y=x If I remember this correctly, which one is negated depends on the direction in which you are moving the object)...
You only have to pull it back along this vector enough for it to touch the line...
After doing so you might also want to change its direction vector by subtracting the normal of the line from direction vector, thus it should now follow the line...
However, if its direction is the opposite of the normal (-normal that is), the object will completely stop...

Something like this was recently discussed on:computer.games.design.programming.algorithms (newsgroup)
Thread is called sliding motion with multiple constraints, but it's slightly more complex than this...
igg -- Take me off for great justice?