Jump to content
  • Advertisement

Archived

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

bjmumblingmiles

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.

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
Advertisement
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
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!