Archived

This topic is now archived and is closed to further replies.

equation for determining vector's angle

This topic is 5517 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to develop an ai to follow another entity in a 2d environment. What is the equation for figuring out the angle the ship needs to face to follow another ship? im sorry i cant articulate this better, so i hope someone understands what i mean. brian

Share this post


Link to post
Share on other sites
A is target
B is your ship

forward is the direction your ship is facing right now

AB=a-b

normalize
cos=dot(AB,forward)

angle=acos(cos)*180/PI

you need to do it in xy and yz plane to find out the yaw and pitch

Share this post


Link to post
Share on other sites
Things get a bit more complicated if you want to try to "head off" your opponent. However, it comes down to the old "what angle do you shoot a bullet at to hit another bullet?" question, which has been answered many times on the Math and Physics forum (and occasionally on the AI one), so check those old posts out. Just "aim ahead" at each timestep!

Share this post


Link to post
Share on other sites