2016-04-17 41 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));