Jump to content

  • Log In with Google      Sign In   
  • Create Account

Finding the Angle between player and mouse (help)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 GDsnakes   Members   -  Reputation: 145

Like
0Likes
Like

Posted 04 December 2012 - 10:46 AM

Ok, I am trying to find the angle between the players position and the mouse. I do this in the following way.


atan ( MouseYposition - PlayerYposition) / (MouseXposition - PlayerXposition).

Now I take this angle and try to apply it to an object I have drawn on screen to see if it works properly. I rotate the object based on where the mouse is.


Heres the problem. The object will only rotate half way. It wont rotate past 90 degress up and it wont rotate past 90 degrees down. So the Angle is pretty much 90> Angle >- 90

I just figured it had to do with the divide by zero at angle = 90 and angle = 270. That would explain why it wouldnt go past those two points (90 up/ 90 down where it would equal 90/270). So I wrote in the code a check for those cases, but the object still wont rotate past those two points.

Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13905

Like
2Likes
Like

Posted 04 December 2012 - 11:04 AM

I haven't read the description of your problem in detail, but I gather it's the type of problem that atan2 is meant to solve:
atan2(MouseYposition - PlayerYposition, MouseXposition - PlayerXposition)

And of course, if you weren't using angles to begin with, this wouldn't be a problem. But perhaps your graphics library requires you to use angles for rotations.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS