Archived

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

equation for determining vector's angle

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

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 on other sites
A is target

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 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 on other sites
Also in the spirit of making things a little more complicated is limiting the turn rate. With an enemy AI it could be rather essential to making it actually playable.

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• Forum Statistics

• Total Topics
631782
• Total Posts
3002332
×