• Advertisement
Sign in to follow this  

angular resolution

This topic is 4829 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

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
Advertisement
In C/C++ you can just use the atan2() function (though it runs in radians, not degrees).

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
Sign in to follow this  

  • Advertisement