Calculating angle between 2 vectors
Posted
by
Error 454
on Game Development
See other posts from Game Development
or by Error 454
Published on 2011-01-07T02:58:06Z
Indexed on
2011/01/07
3:00 UTC
Read the original article
Hit count: 225
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?
© Game Development or respective owner