1.使用四元数
目标点-当前点,计算即将forward的方向,根据rotspeed在update里面一点点插值过去。
void RotateTo()
{
Vector3 dir = m_CurrentPathNode.transform.position - Tran.transform.position;
dir.y = 0;
Quaternion q = Quaternion.LookRotation(dir);
Tran.rotation = Quaternion.Slerp(Tran.rotation, q, RotSpeed);
}
2.RotateTowards改变当前forward
Vector3.Angle(RotObj.transform.forward, temp - RotObj.transform.position) 计算目标与物体指向前方之前的夹角
Vector3 dir = temp - RotObj.transform.position;
Tran.forward = Vector3.RotateTowards(RotObj.transform.forward, dir, RotSpeed * Time.deltaTime, 0); Update控制旋转