我想要一个对象远离触摸事件的位置。Libgdx:将身体从触摸事件中移开
到目前为止,我有以下几点:
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 touchPosition = new Vector3();
camera.unproject(touchPosition.set(screenX, screenY, 0));
Vector2 directionBody = body.getPosition();
Vector2 directionTouch = new Vector2(touchPosition.x, touchPosition.y);
Vector2 direction = directionBody.sub(directionTouch);
direction.nor();
float speed = 3;
body.setLinearVelocity(direction.scl(speed));
return true;
}
使用此代码,如果我按在身向左移动屏幕的右侧。如果在屏幕左侧按下,身体会移到右侧。有人可以帮我吗?
非常感谢,我会仔细研究一下。 – Markus