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 implement some 2D vehicle physics. For this to work I have 2 wheels attached to the body of the car. After doing some collisions checks I place the wheels at their new position. Say the first wheel is at (-0.5, 1) and the second wheel is at (0.5, 1) I now have to calculate the angle and position of the body between the wheels. In the given example the angle should be 0. But how do I calculate the angle?

Because pictures make everything easier: The blue lines are the positions of the wheels and the pink line is the body. Given the two positions of the wheels, at what angle is the body in relation to the ground?

Situational sketch

share|improve this question
I don't understand the image. Is this top-down view? Why is the wheel on the right larger than the one on the left? – bummzack Dec 15 '11 at 10:58
Hmm, yes the image isn't too clear, sorry. But I meant the blue lines to be vectors from Y=0 to indicate the position – Roy T. Dec 15 '11 at 11:02
Oh I see. So the pink line is the wheels axis? – bummzack Dec 15 '11 at 11:06
Yeah exactly that – Roy T. Dec 15 '11 at 11:28
up vote 1 down vote accepted

All you need is atan2:

angle = atan2(frontwheel.y - rearwheel.y, frontwheel.x - rearwheel.x);
share|improve this answer
You're absolutely right, I was just thinking too difficult! – Roy T. Dec 15 '11 at 11:57

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.