Java Libgdx玩家轮换混乱

Java Libgdx玩家轮换混乱,java,android,libgdx,Java,Android,Libgdx,我正在尝试编程一个朝鼠标旋转并以一定速度朝鼠标移动的播放器。我使用的是正交摄影机,但是,只要我将摄影机的位置设置为与玩家的位置相等,玩家的旋转就会停止工作并四处移动。我相信这可能与使用屏幕的鼠标坐标有关,而不是世界x和y。我已尝试将Gdx.inout.getY/X取消投影为no-previval。非常感谢您的帮助 我使用此代码跟踪玩家: cam.position.x = player.getX(); cam.position.y = player.getY(); cam.

我正在尝试编程一个朝鼠标旋转并以一定速度朝鼠标移动的播放器。我使用的是正交摄影机,但是,只要我将摄影机的位置设置为与玩家的位置相等,玩家的旋转就会停止工作并四处移动。我相信这可能与使用屏幕的鼠标坐标有关,而不是世界x和y。我已尝试将Gdx.inout.getY/X取消投影为no-previval。非常感谢您的帮助

我使用此代码跟踪玩家:

    cam.position.x = player.getX();
    cam.position.y = player.getY();
    cam.update();

And this code for rotation:
float mouseX = Gdx.input.getX();
                float mouseY = (480 - Gdx.input.getY());

                float originX = getWidth() / 2 + position.x;
                float originY = getHeight() / 2 + position.y;

                double angle = Math.atan2(mouseY - originY, mouseX - originX) * (180/Math.PI) + 90;

                if (angle < 0) 
                      angle += 360;

                rotation = (float) angle;

                direction.x = mouseX - position.x;
                direction.y = mouseY - position.y;

                double hyp = Math.sqrt(direction.x * direction.x + direction.y * direction.y);
                direction.x /= hyp;
                direction.y /= hyp;

                position.x += direction.x * 2;
                position.y += direction.y * 2;
cam.position.x=player.getX();
cam.position.y=player.getY();
cam.update();
这是轮换的代码:
float mouseX=Gdx.input.getX();
float mouseY=(480-Gdx.input.getY());
float originX=getWidth()/2+position.x;
float originY=getHeight()/2+position.y;
双角度=数学atan2(mouseY-originY,mouseX-originX)*(180/数学PI)+90;
如果(角度<0)
角度+=360;
旋转=(浮动)角度;
方向.x=鼠标位置.x;
方向.y=鼠标-位置.y;
double hyp=Math.sqrt(direction.x*direction.x+direction.y*direction.y);
方向x/=hyp;
方向y/=hyp;
位置x+=方向x*2;
位置y+=方向y*2;
您是否尝试投影(或取消投影)点

ViewPort viewPort = new ... // which ever ViewPort you're using

Vector2 worldPoint = new Vector2(x, y);
Vector2 projected = viewPort.project(worldPoint);


对不起,我对这些东西不熟悉,所以我创建了一个新的视口,并将其设置为我的相机?我的世界点是什么?播放器的位置?对不起,我假设您已经在使用视口。搜索StretchViewport(有一个不同的视口可用,我在当前项目中使用此视口)-您应该能够以这种方式找到您的答案…谢谢,我使用screen Viewport并以这种方式取消投影。
Vector2 screenPoint = new Vector2(x, y);
Vector2 unprojected = viewPort.unproject(screenPoint);