How to get cursor position in libgdx and apply it to sprite? Like this?
I want my
I usually track my mouse into world coordinates like this:
// variables
private final Vector2 mouseInWorld2D = new Vector2();
private final Vector3 mouseInWorld3D = new Vector3();
private final OrthographicCamera cam;
.
.
.
//in render() code
mouseInWorld3D.x = Gdx.input.getX();
mouseInWorld3D.y = Gdx.input.getY();
mouseInWorld3D.z = 0;
cam.unproject(mouseInWorld3D);
mouseInWorld2D.x = mouseInWorld3D.x;
mouseInWorld2D.y = mouseInWorld3D.y;
Then, I can use mouseInWorld2D to access mouse coordinates (relative to the scene/world) in my game. A sprite can track that coordinate very easy and compute its angle and direction.