簡體   English   中英

unity3d 太空射擊運動

[英]unity3d spaceshooter movement

大家好,我的宇宙飛船的旋轉有一些問題。 如果我按下左箭頭,然后切換到右箭頭,旋轉會立即切換。 我怎樣才能平滑它?

視頻: 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);
}

}

如果您想要逼真的物理效果,請不要直接修改剛體的位置或旋轉。 而是使用Rigidbody.AddForce為直線運動,並Rigidbody.AddTorque旋轉。

要平穩地旋轉船,您可以執行以下操作:

float speed = 10f;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM