如何使 Vector3.Slerp实现平滑的运动

xiaoxiao2021-02-28  28

static function Vector3 Slerp (Vector3 from, Vector3to, float t) Spherically interpolates between two vectors. 球形插值在两个向量之间。

可以看到官方文档里表示该值为两个向量之间的差值

如果想要该使用该函数进行一次圆形运动,那么两个V3的向量需要从球心出发指向两个球面上的点。通过改变球心的位置可以更改圆形形成的弧度。匀速运动 参数t从0到1表示运动的进度,因此t需要为一个从0到1匀速增加的数,代码如下 /// <summary> /// 开始移动 /// </summary> public void BeginMove() { time = Time.time; } void FixedUpdate() { if (inMove) { //弧形插值 transform.position = Vector3.Slerp(start, end, (Time.time-time) *Time.fixedDeltaTime* moveSpeed); transform.position += center; } }

其中center表示球心

转载请注明原文地址: https://www.6miu.com/read-1700085.html

最新回复(0)