Joke-crazy
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);
    }
}
View Code

转载:https://blog.csdn.net/qq_25210959/article/details/51713408

分类:

技术点:

相关文章:

  • 2021-11-11
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-10-11
  • 2021-10-10
  • 2021-10-16
猜你喜欢
  • 2021-07-12
  • 2021-07-20
  • 2021-09-30
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案