Unity 根据前后帧位置自动旋转
写在Update里面
var newPos = transform.position; if (lastPos != newPos) { targetRotation = Quaternion.LookRotation(newPos - lastPos); } if (Math.Abs(transform.rotation.eulerAngles.y - targetRotation.eulerAngles.y) > 0.01f) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(new Vector3(0, targetRotation.eulerAngles.y, 0)), rotateSpeed); } lastPos = newPos;