Wasn't sure which board to post this in but nevertheless. If it needs moving, move it.
I'm working on a game and I need help with some math.
What I'm trying to do is get the angle (direction) of the mouse cursor relative to the object checking the angle.
I've applied what I have learned from class but I'm not sure if I'm doing it quite right here.
boolean direction = Math.atan(yy/xx)/Math.PI*180;
This works mostly as I get an angle returned, and in degrees not radians.
Only the angle passes from 0 to 90 and 0 to -90. Repeating itself at certain angles that would otherwise be something like 200 degrees.
The other problem is xx and yy can be negative, because the values are relative to the object on the screen.
boolean xx = input.x - x;
boolean yy = input.y - y;
I tried by forcing the values to always be positive but the angles were still messed up.
But don't get me wrong, this all works from 0 to 90 degrees flawlessly. Although if I go to around where 360-270 degrees should be, it shows 0 to -90 degrees instead.
It's like a sine wave all the way around: 0 to 90, 90 to 0, 0 to -90, -90 to 0.
I'd just rather this go from 0-360 all the way around. If anyone can help I'll be most thankful