Problem with rotating player to fave the mouse location

So my player acts like it is going to rotate to face the mouse but it doesn’t quite work. It pivots from the center of the player.
Sorry if I am not being very specific, Im not really sure on how to explain the problem.

http://pastebin.java-gaming.org/96927868d2c1e
This is how I am rotating the player.

Can anyone see what I am doing wrong?

Although I’m not clear from your description exactly what’s going wrong, I did notice this:

float angle = (float)(Math.atan2(centerY - mouseY, centerY - mouseX));

The second argument should be ‘centerX - mouseX’ (presumably).

Also, I think typically those argument would be negated (e.g. ‘mouseY - centerY’), but maybe you have them that way for a reason.

I changed that but when I Move the mouse around the object I want to rotate, it moves a little and then just glitches. Ill try to get an example.

Perhaps you could post your updated code. Also, I’m not sure how the transform API you’re using works, but make sure you’re not concatenating the rotation repeatedly with a previous transform.

Another thing to check is that the mouse coordinates and player coordinates are in the same coordinate system.

If you’re still having problems, try printing out the arguments to atan2(), and the resulting angle (maybe in degrees for readability), and see if/how they differ from what you’d expect.

You are right! My coord systems are different for both the mouse and the player. Ill let you know when I get them lined up.

What I decided to do was make a crosshair entity and follow that