Direction of normal - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Direction of normal (/thread-8171.html) Direction of normal - Miglu - Oct 4, 2010 12:25 PM I want to make a circle bounce from surfaces when a key is pressed in the way that the ball in N-Ball does, so that its velocity in the direction of the surface's normal becomes a value that has a constant magnitude and its velocity in the direction that is parallel to the surface does not change. This is not a physics engine question, only a mathematical one. How to do it? I am asking this as I can not yet do vector maths well (I know only its basics). RE: Direction of normal - Skorche - Oct 4, 2010 01:05 PM Simple, you just need to subtract out the normal component from the velocity. Velocity component parallel to the normal: vNormal = dot(velocity, n)*n Velocity component perpendicular to the normal: vTangent = velocity - vNormal Your desired normal velocity: vDesired = n*desired Putting it all together: vResult = vTangent + vDesired Which simplifies to: vResult = velocity + (desired - dot(velocity, n))*n RE: Direction of normal - Miglu - Oct 4, 2010 01:56 PM Thanks. Do I need to find the collision surface's normal myself, as Chipmunk does not seem to have a query for it? RE: Direction of normal - Skorche - Oct 4, 2010 05:08 PM You can get collision normals from the cpArbiter struct passed to your collision handler callback. (See http://files.slembcke.net/chipmunk/release/ChipmunkLatest-Docs/#cpArbiter)