using UnityEngine; public class PlayerController : MonoBehaviour { public float turnspeed = 10; float ver = 0; float hor = 0; void Update() { hor = Input.GetAxis("Horizontal"); ver = Input.GetAxis("Vertical"); } void FixedUpdate() { if (hor != 0 || ver != 0) { //转身 Rotate(hor, ver); } } void Rotate(float hor, float ver) { //获取方向 Vector3 dir = new Vector3(hor, 0, ver); //将方向转换为四元数 Quaternion quaDir = Quaternion.LookRotation(dir, Vector3.up); //缓慢转动到目标点 transform.rotation = Quaternion.Lerp(transform.rotation, quaDir, Time.fixedDeltaTime * turnspeed); } }
转载:https://blog.csdn.net/qq_25210959/article/details/51713408