2016-08-24 135 views
0

我正在爲我的項目使用InControl input manager。我正在使用來自右側棒的輸入來旋轉我的播放器對象,但我希望播放器能夠平滑而不是瞬間旋轉。InControl - 如何平滑旋轉播放器

這裏是我當前的代碼:

void FixedUpdate() 
{ 
    var device = InputManager.ActiveDevice; 

    MoveThePlayer(device.LeftStick.X, device.LeftStick.Y); 
    RotateThePlayer(device.RightStick.X, device.RightStick.Y); 
} 


void MoveThePlayer(float movex, float movey) 
{ 
    body.velocity = new Vector2(movex * speed, movey * speed); 
} 

void RotateThePlayer(float movex, float movey) 
{ 
    float heading = Mathf.Atan2(movey, movex); 
    transform.rotation = Quaternion.Euler(0f, 0f, heading * Mathf.Rad2Deg); 
} 
+0

請註明我的答案是正確的或指定什麼是錯的我的反應。 –

回答

0

Lerps是你的朋友。

transform.Rotate()你對使用Time.deltaTime

例如,你想要的角度玩家:

transform.Rotate(0, 0, (angleIWantToBeAt - transform.eulerAngles.z) * Time.deltaTime * speedMultiplier)