I have a Body that I want to move towards the touch position (screenX, screenY). My current method for doing this works, but only for when the screen resolution is the same as the viewport width and height.
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
Vector3 touch = camera.unproject(new Vector3(screenX, screenY, 0));
Vector2 direction = new Vector2((touch.x - currentBody.getPosition().x), (touch.y - currentBody.getPosition().y));
//normalise, scale etc...
I think the part I’m stuck on is converting the camera coordinate to the Box2D coordinate. When I resize the window, the Body doesn’t move directly at the mouse, it’s a bit off. I’m using a FitViewport with a virtual resolution of 640x1136