Unity ----Quaternion.Slerp---- 缓慢转向的使用

using UnityEngine;
using System.Collections;
 
public class test : MonoBehaviour
{
    public float angleSpeed = 0.01f;
    public Transform target;
    public bool isRotate = true;
 
    void Update()
    {
        Vector3 vec = (target.position - transform.position);
        Quaternion rotate = Quaternion.LookRotation(vec);
        if (Vector3.Angle(vec, transform.forward) < 0.1f)
        {
            isRotate = false;
        }
        if (isRotate)
        {
            transform.localRotation = Quaternion.Slerp(transform.localRotation, rotate, angleSpeed);
        }
    }

}

猜你喜欢

转载自blog.csdn.net/liyangufo/article/details/129939919