I need the sprite to hit the cursor / touchpoint. The vector of the touch point is calculated as follows:
game.getCamera().unproject(
new Vector3().set(Gdx.input.getX(), Gdx.input.getY(), 0)
, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight())
And then I calculate the degrees that the sprite should handle with the following method:
public void rotateTo(Vector3 vector) {
double angle = Math.atan2(vector.y - position.y, vector.x - position.x);
rotation = (float) Math.toDegrees(angle) - 90;
sprite.setRotation(rotation);
}
The problem is that, for example, there is a slight shift in some turns (the red dot indicates the position of the touch, and the arrow indicates the sprite that needs to be rotated), in the first figure it’s about the way it should be, but in its other ways, that could be the cause of this error ?:


As you can see in the first two pictures with a slight change in the X axis, the accuracy decreases sharply.
Other examples:


source
share