How can I calculate the angle between two 2D vectors?
- by Error 454
I am working on some movement AI where there are no obstacles and movement is restricted to the XY plane. I am calculating two vectors, v, the facing direction of ship 1, and w, the vector pointing from the position of ship 1 to ship 2.
I am then calculating the angle between these two vectors using the formula
arccos((v · w) / (|v| · |w|))
The problem I'm having is that arccos only returns values between 0° and 180°. This makes it impossible to determine whether I should turn left or right to face the other ship.
Is there a better way to do this?