2016-08-16 28 views
1

相機旋轉後,座標對我來說很混亂。rotationground camera後的Libgdx座標

我有一個相機的角色和地圖。 此球員只能朝北方向(90°),南方(270°),東方(0°),西方(180°)方向行走。

Before rotation

從玩家camera.rotateAround(...,...,...)「的位置旋轉攝像頭後,玩家開始在新的方向移動作爲旋轉的結果。

After rotation

有沒有辦法重新定位將原先的座標,而不地圖移動到原來的位置?

  • 注意:軌道圖是暫時的,然後有這些鬆散膠合的邊緣。

我很感激幫助。

回答

1

首先你需要存儲地圖的旋轉角度。 然後當玩家移動時,你需要考慮地圖的旋轉角度。

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. 

現在你知道旋轉,所以你可以用三角函數設置玩家的移動。

in player.moveup(float 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

正如你可以當攝像頭也旋轉方向旋轉看到。所以你只需要減去地圖旋轉來糾正。

enter image description here

+0

謝謝先生。 Deniz – Lovera

+0

不客氣:) –

+0

嗨德尼茲,我正在研究你所提到的三角學。即使如此,我還有一個問題。請問你能幫幫我嗎。 http://stackoverflow.com/questions/39028834/libgdx-fixed-point-after-camera-rotatearound – Lovera