I am using the current mouse position to aim the player sprite, but I am not getting the best results.
It will often by off by a noticeable amount, or even a complete ~180 off if I go from one side, through the player, to the other side.
boolean mouseMoved(int screenX, int screenY) {
mouseX = screenX;mouseY = screenY;
rot = MathUtils.radiansToDegrees * MathUtils.atan2((float)mouseY - (float)player.y, (float)mouseX - (float)player.x);
if (rot < 0) rot += 360;
player.setRot(rot);
}
Update 1:
When I am at 90/270 it seems to pickup the angle fine. But for 0/180, the angle is off depending on how far away my cursor is to a certain point (not the player's point).
Update 2:
Added in semi-fix, but I'm still having the same exact problem
Update 3:
I was mistaken the semi-fix wasn't actually a fix. I fixed it for real, though. The problem was that libgdx has (0,0) at the bottom left, but the InputProcessor has (0,0) at the top left. What I had to do was adjust the mouse position so that it's (0,0) was the bottom left. I did this by
mouseX = screenX;
mouseY = Game.HEIGHT - screen y;
This will give the player coordinates & mouse coordinates the same origin, and then the formula will work.