# find direction from point A to point B

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

## Recommended Posts

I'm not very good at math, but heres what I'd like to do ...

I have an object located on a 2d grid, so I know its current point. I get direction by moving the point a short distance in the forward direction so I know where its pointing. My target location is a secondary point. My goal is to find direction to the next point.

So basically, I just want to turn my object to the correct angle and move it to a specified location.

Can anyone help w/ how this is done?

##### Share on other sites
The direction that goes from point A to point B is indicated by the vector V = B - A. It is convenient to represent a direction by a unit-length vector, so you may want to normalize that vector.

An alternative representation of a direction in 2D is an angle (typically measured from the positive x axis and going counterclockwise). You can obtain that as

angle = atan2(V.y, V.x)

But, as has been mentioned many times in several recent threads, you can usually avoid using the angle because most of the time all you want to do is compute its sine and cosine, which you already know (cos(angle) = V.y and sin(angle) = V.x, if V has been normalized ). Using unit vectors (or unit complex numbers, which is almost the same thing) instead of angles often requires fewer special cases, and the resulting code tends to be cleaner, faster, easier to read and easier to get right.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015570
×