[Solved] Rotation towards mouse is wonky.

// Point to mouse
		float dX = Gdx.input.getX() - position.x;
		float dY = Gdx.input.getY() - position.y;
		direction = (float) Math.atan2(dY, dX);
		direction = (float) Math.toDegrees(direction);

How do I fix my math?

You just gave us code. What does the output look like?

https://s12.postimg.org/68jak93a5/Screenshot_from_2016_09_07_23_50_05.png

Mouse is at the top left the darker more shadow-y part at the bottom right is where it should be pointing. This isnt a constant pattern though, as move it to a different location provides a different pattern result.

Moving my mouse on the x-axis from left to right gives this result. This is dragging it above the object

-74.87599
-68.869156
-66.876205
-61.487274
-58.022465
-54.80065
-51.815426
-48.87992
-46.018833
-42.49766
-40.471176
-38.840836
-37.318096
-36.000748
-34.418365
-33.216953
-32.07588
-30.922367
-30.393263
-29.725626
-29.15832
-28.586416
-28.028736
-27.448467
-26.694023
-26.056334
-25.565445
-25.025211
-24.298592
-23.432734
-22.783596
-21.824541
-21.30122
-20.816927
-20.438267
-20.092564
-19.7579
-19.284763
-18.401106
-18.083445
-17.64562
-17.095224
-16.490276
-16.364544
-15.892183
-15.422161
-15.003985
-14.722321
-14.527848
-14.516302
-14.504772
-14.493262
-14.470294
-14.447397
-14.424571

Try flipping the y:


float dY = position.y - Gdx.input.getY();

Figured out the problem, had to unproject my mouse coordinates. Thanks for the help!


	// Point to mouse
		mousePos.x = Gdx.input.getX();
		mousePos.y = Gdx.input.getY();
		camera.unproject(mousePos);
		float dX = mousePos.x - position.x;
		float dY = mousePos.y - position.y;
		direction = (float) Math.atan2(dY, dX);
		direction = (float) Math.toDegrees(direction);
		System.out.println(direction);