   Relative Velocity ?
  Hi guys,When I have two moving objects I use their relative velocity for the collision detection, like this:RelVel = ObjectA.velocity - ObjectB.velocity;Then I treat ObjectB as stationary and see if ObjectA hits it.Now, if it does hit what velocity do I reflect in the collision response ? Do I reflect ObjectA.vel or RelVel ?For example, let''s say a ball is heading toward and hits a stationary wall, then I reflect the velocity of the ball off the wall normal. But what if the ball is heading away from the wall and the wall is heading the same direction but faster so it hits the ball in the ass (which I detected using their relative velocity), how do I reflect ?Thanks. 
  this becomes a matter of momentum now, where the conservation of mass*velocity will hold truem1*v1 + m2*v2 = m1*v3 + m2*v4this can''t be solved though, just knowing their initial velocities and masses, you need to have some other condition for their collision, like knowing what velocity one of them will be AFTERwards, then calculating the other. ;  you could use the conservation of kinetic energy as the second conditionm1*v1^2/2 + m2*v2^2/2 = m1*v3^2/2 + m2*v4^2/2this would be an elastic condition.the collision is totally inelastic if the two objects stick together and have got the same velocity after the collisionv3 = v4realistic collisions are somewhere between these two extremes.for a specific collision you could use the condition that a certain fraction of the kinetic energy as seen from the center of gravity gets lost (that means converted to heat or whatever)in the frame of reference of the center of gravity i''ll call the velocities v1'' and v2'' and the momentum is 0:m1*v1'' + m2*v2'' = 0but the relative velocity must be the samev1'' - v2'' = v1 - v2from these 2 equation you can compute v1'' and v2''.the difference v1 - v1'' = v2 - v2'' = v_cogis the velocity of the center of gravity.now you can do the collision using v1'' and v2'' with the momentum condition and the condition that the kinetic energy after the collision is only a certain fraction A of the kinetic energy before collision:A*(m1*v1''^2/2 + m2*v2''^2/2) = m1*v3''^2/2 + m2*v4''^2/2convert the resulting velocities v3'' and v4'' back to worldspace by adding v_cog.