Line to point response

Started by
5 comments, last by FreeDebreuil 18 years, 6 months ago
I'm doing a simple 2d physics engine and I'm trying to get a point to bounce off a line. I already know which line it is hitting, all the angles, ect... Any help appreicated (btw, my angles go ccw).
Advertisement
Generally this sort of thing is done with vector math rather than angles and trig. A simple way to 'bounce' an object is to reflect the velocity vector about the line (or plane in 3d) normal. The equation for vector reflection is:
v' = v - 2(v.n)n
Where n is the unit-length normal.
hmmm, guess I'll convert the angle into a vector... Thanks!
ToyBox 2D physics engine code/exe

Check out PhysicsEngine/PhysicalObject.cpp and look at the collisionResponse function for falling object. Do your bounces like that.

Thanks, you made that engine...?
Yes, and I'm still hacking away on it. :-D It's been in serious development for about 6 months off and on.

nice, hopefully I can make something around that level :D

This topic is closed to new replies.

Advertisement