首页 文章

Libgdx在rotateAround摄像机后进行坐标

提问于
浏览
2

相机旋转后,坐标让我感到困惑 .

我有一个相机角色和 Map . 该玩家仅在以下方向行走:北(90°),南(270°),东(0°),西(180°) .

Before rotation

从播放器'camera.rotateAround(...,...,...)'的位置旋转相机后,播放器因旋转而开始向新方向移动 .

After rotation

有没有办法将原稿重新定位回坐标而不将 Map 移动到原始位置?

  • 注意:轨道 Map 是临时的,然后有这些松散的胶合边缘 .

我很感激帮助 .

1 回答

  • 1

    首先你需要存储 Map 的旋转角度 . 然后当玩家移动时你需要考虑 Map 的旋转角度 .

    camera.rotatearound(...)//I guess you rotating +90 or -90 in this game 
    maprotation+=... //+90 or -90 depends on side you turn.
    //i ll assume rotation direction is counter clock wise.
    

    现在你知道了旋转,所以你可以用三角法设置玩家的移动 .

    在player.moveup(浮动maprotation)方法或者你编写代码移动到北方时 .

    x+=MathUtils.cosDeg(90-maprotation)*speed;//90 degree for moving up
    y+=MathUtils.sinDeg(90-maprotation)*speed;// - maprotation for correction
    

    enter image description here

    正如你所看到的那样,相机旋转时方向也会旋转 . 所以你只需要减去 Map 旋转来纠正 .

    enter image description here

相关问题