2016-04-17 42 views
-2

夥計們,我有一些問題,我的太空船的旋轉。如果我按左箭頭,並切換到右箭頭旋轉即時切換。我如何平滑它?unity3d太空射擊運動

視頻: https://sendvid.com/fek9izy3

void FixedUpdate() 
{ 
    Rigidbody rb = GetComponent<Rigidbody>(); 
    float moveHorizontal = Input.GetAxis("Horizontal"); 
    float moveVertical = Input.GetAxis("Vertical"); 

    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); 
    rb.velocity = movement * speed; 

    rb.position = new Vector3 
    (
     Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 
     0.0f, 
     Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) 
    ); 

    rb.rotation = Quaternion.Euler(0.0f, 180, rb.velocity.x * -tilt); 
} 

}

回答

0

如果你想真實的物理,不直接修改剛體的位置和旋轉。請使用Rigidbody.AddForce進行直線運動,並使用Rigidbody.AddTorque進行旋轉。

以平穩地旋轉船,你會做這樣的事情:

float speed = 10f; 

rb.AddTorque(new Vector3(0f, 0f, moveHorizontal * speed));