Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to figure out a way to determine the relative velocity of a body colliding with another in a 2D environment.

For example if one body is moving at (1,0) and another traveling behind it collides with it from behind at (2,0) the velocity of the impact relative to the first body was (1,0).

I need a method which takes in two velocities, one velocity belonging to the body the velocity is being measured against, and the other for the impacting body and return the relative velocity.

share|improve this question
up vote 10 down vote accepted

This is a simple operation of vector difference. In XNA you don't even need to create a specific method for it - vectors already support subtraction.

If you want the velocity of Body B from the perspective of Body A, you subtract Body A's velocity from Body B.

So in C# with XNA, using your example:

Vector2 MovingBody = new Vector2(1, 0);
Vector2 Impact = new Vector2(2, 0);
Vector2 PerceivedImpact = Impact - MovingBody;
// PerceivedImpact equals (1, 0) in this scenario
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.