Calculating angle between 2 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 2 vectors:
v - the direction of ship 1
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 standard formula:
arccos( v . w / ( |v| |w| ) )
The problem I'm having is the nature of arccos only returning 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?