Sign in to follow this  
Kaze

angular resolution

Recommended Posts

im making a rpg where you move the character by clicking a point and letting you character move there(like starcraft and red alert 2) does anyone know a way to find the angle between two points that works for 0-360 insted of 0-90 and is more gracefull that combining the 0-90 one with if statments EDIT:sorry can anyone move this to math and physics section

Share this post


Link to post
Share on other sites
As SiCrane already said, use atan2:

double dAngle = atan2( deltax, deltay );

deltax is the difference in x, deltay the difference in y.
The resulting angle is in radian, you can store it that way or transform to degree by multiplying with 180.0f / PI.

Also, you might take in account that y on the screen is usually downwards, while mathematically y points up (If you need to do that you just use -deltay in atan2).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this