簡體   English   中英

Unity對象不旋轉

[英]Unity object not rotating

我正在嘗試在特定邊界內旋轉對象,但是該對象不會旋轉。

public class shincon : MonoBehaviour
{
    Rigidbody rb2;
    float shinspeed = 10;

    // Use this for initialization
    void Start()
    {
        rb2 = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float Posax = Input.GetAxis("leftshin");
        if (Posax != 0)
        {
            Vector3 move = new Vector3(shinspeed * Posax * Time.deltaTime, 0, 0);
            transform.rotation = Quaternion.identity;
            Vector3 euler = transform.rotation.eulerAngles;
            float clampx = Mathf.Clamp(move.x + euler.x, 0, 160);
            Vector3 ready = new Vector3(clampx - euler.x, 0, 0);
            Quaternion rmove = Quaternion.Euler(ready);

            rb2.MoveRotation(rb2.rotation * rmove);
        }
    }
}

沒有語法錯誤,但不會旋轉。

下線后

transform.rotation = Quaternion.identity;

下一個

Vector3 euler = transform.rotation.eulerAngles;

將始終返回0,0,0

並進一步

Quaternion rmove = Quaternion.Euler(ready);

最終產生Quaternion.Identity

rb2.MoveRotation(rb2.rotation * rmove);

始終會產生Quaternion.Identity也將使對象永遠不會旋轉。


刪除線

transform.rotation = Quaternion.identity;

暫無
暫無

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

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