物體旋轉到指定角度

 public float Speed;
    Quaternion targetAngels;
    
    public GameObject gam;

    // Use this for initialization
    void Start () {
        targetAngels = Quaternion.Euler(90, 0, 0);
    }

    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.name == "Sphere")
        {
            //速度隨旋轉角度的接近減慢
            this.gameObject.transform.rotation = Quaternion.Slerp(transform.rotation, targetAngels, Speed * Time.deltaTime);

            //速度恆定旋轉
            this.gameObject.transform.rotation = Quaternion.RotateTowards(transform.rotation, targetAngels, Speed * Time.deltaTime);
        }
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章