equation for determining vector's angle

Started by
2 comments, last by bjmumblingmiles 21 years, 5 months ago
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
Brian J
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
http://www.8ung.at/basiror/theironcross.html
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!
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.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement