Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

Given three points on the same Y plane;

  • A ship
  • A point along the ships heading
  • A mouse cursor

How can I find which direction and angle the mouse cursor is from the ships heading?

I have a limited turn speed on the ship - so I can not simply point the ship at the mouse, but tell it to steer left or right until it faces in the same direction of the mouse.

share|improve this question
up vote 2 down vote accepted

ship_dir =point_on_heading-ship_pos(ition) //vector ship is heading in
mouse_dir=mouse_pos-ship_pos               // vector from ship to mouse position

You can find the angle between these two vectors;

ship_dir.Normalize(); //divide by length
mouse_dir.Normalize();//divide by length
angle=acos(dot_prod); //cos-1, this will give angle between two vectors

BUT that doesn't tell you which way to turn (left or right)(positive or negative)(clockwise or anti-clockwise).

You also need to consider the normal to the mouse_dir. The dot product between two vectors is positive if the angle is less than 90deg.

if(dot_prod>0) //+ive value means the angle is <90deg therefore, ship_dir is on 'left'side of mouse dir, so clockwise is shortest route
    rotate clockwise;
    rotate anti_clockwise;

enter image description here

share|improve this answer
perfect! for those following at home, to match my exact problem, my mouse normal is set as mouse_position(z,1,x); – salmonmoose Nov 4 '12 at 12:34

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.