Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么矢量3.Lerp不平滑?_C#_Unity3d_Vector_Rotation - Fatal编程技术网

C# 为什么矢量3.Lerp不平滑?

C# 为什么矢量3.Lerp不平滑?,c#,unity3d,vector,rotation,C#,Unity3d,Vector,Rotation,我试图让我的第三人称播放器的赞美之词变得过于平淡,但这并没有真正起作用。 我使用“Vector3.Lerp”,但什么也没发生 如果有人能帮我,我会很高兴的 public float speed = 5f; public Transform relativeTo; private Rigidbody rb; void Start(){ rb = GetComponent<Rigidbody>(); } void Update() { Move(); } priv

我试图让我的第三人称播放器的赞美之词变得过于平淡,但这并没有真正起作用。 我使用“Vector3.Lerp”,但什么也没发生

如果有人能帮我,我会很高兴的


public float speed = 5f;
public Transform relativeTo;
private Rigidbody rb;

void Start(){
    rb = GetComponent<Rigidbody>();
}

void Update()
{
    Move();
}

private void Move()
{
    float vertical = Input.GetAxis("Vertical");
    float horizontal = Input.GetAxis("Horizontal");

    if (vertical != 0 || horizontal != 0)
        Rotate();

    Vector3 movement = new Vector3(horizontal, 0, vertical) * speed * Time.deltaTime;
    transform.Translate(movement);
}

private void Rotate()
{
    Vector3 desiredRotation = new Vector3(0, relativeTo.eulerAngles.y, 0);
    this.transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, desiredRotation, 1f);
}

公共浮子速度=5f;
公共关系;
私人刚体;
void Start(){
rb=GetComponent();
}
无效更新()
{
Move();
}
私人空位移动()
{
float vertical=Input.GetAxis(“垂直”);
float horizontal=Input.GetAxis(“水平”);
如果(垂直!=0 | |水平!=0)
旋转();
Vector3移动=新Vector3(水平、0、垂直)*速度*时间增量;
变换。翻译(运动);
}
私有空间旋转()
{
Vector3 desiredRotation=新的Vector3(0,相对于.eulerAngles.y,0);
this.transform.eulerAngles=Vector3.Lerp(transform.eulerAngles,desiredRotation,1f);
}

Lerp函数的第三个参数可以设置更改的平滑度。
将最后一行更改为:

this.transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, desiredRotation, Time.deltaTime * speed);
定义一个float
speed
变量并将您的值设置为它(我认为2或2.5是好的)