7

I am programming some movement for AI for a game based on angle and speed.Its a 2D program based on x,y axis. I currently have a position vector as-well as a velocity vector which accounts for speed and current direction of the AI.Every time I move the AI I just add the velocity vector to the current position to get my new position.At the moment the movement is 8-directional.What I wanted to implement was angle based movement (more realistic type of movement) and wondered if it is possible to calculate the velocity vector from an angle and speed constant.

Thanks in advance!

1
  • 1
    Have a look at any basic linear algebra book. (Or try a scatch on a paper.)
    – MrSmith42
    Dec 29, 2012 at 23:14

1 Answer 1

17

This better be possible.

This is how I envision your program works

position_X += velocity_X
position_Y += velocity_Y

Through trigonometry you can do

velocity_X = velocity*cos(angle)
velocity_Y = velocity*sin(angle)

enter image description here

A few things to keep in mind include

  1. Most likely Y increases as you go from top to bottom
  2. The inverse problem has two solutions, you should look into a 2 input arctangent function. See https://gamedev.stackexchange.com/questions/14602/what-are-atan-and-atan2-used-for-in-games
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.