Archived

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

Fast angle calculation between two points

This topic is 5579 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''ve been trying to find a fast way of getting the angle between two points. What I have is this one object in the game who is supposed to chase after another object (straight line). The game is basically 2d (uses 3d models for graphics but the gameplay is all 2d). I was wondering if maybe I should use vectors but I really am not sure where to go. I''d search the forums but the search thing is broken right now.

Share this post


Link to post
Share on other sites
You should use vectors, but in the mean time:
x1 * x2 + y1 * y2 = sqrt(x1² + y1²) * sqrt(x2² + y2²) * cos(angle)

This is the definition of the dot product. If you have two vectors (x1, y1) and (x2, y2), then you can use this formula to find the angle.

There are some introductions to vectors here on GameDev, if you don''t know how to use them.

Cédric

Share this post


Link to post
Share on other sites