完整的写法:public static Vector3 Lerp(Vector3 a,Vector3 b,float t);
首先看一下API是怎么说的:
Linearly interpolates between two vectors. Interpolates between the vectors |
个人渣渣翻译:在两个向量之间线性的插值。通过插值t在向量a和b之间插入。参数t在[0,1]的范围内。这是在两点之间的直线上找到一个点的最常用的方法(例如:在这些点之间逐渐移动物体)。当t=0是返回a,当t=1是返回b。当t=0.5是返回a,b的中点。
忽略翻译,重点就是:t是一个百分比,表示从a向b移动多少比例。用数学表示,移动后的位置为a+(b-a)*t。
这样子看来,这个方法很鸡肋啊,虽然能移动到目标位置,但不能控制移动的时间。假如想知道怎么一定时间移动到目标位置的话,请看我的博客《四种移动到目标位置的方式》。我们还是回到这里,这个有什么用呢?
- 假如t中有Time.deltaTime时,虽然不可用于两点之间的移动,但可用于摄像机跟随;
- 若t=Time.time,则表示1s移动到b,这稍微可以控制一下时间;
- 因为是插值运算,所以说平滑的;
- 更多的用法,等我探索以后再来补充-_-
具体使用方法就是:
transform.position=Vector3.Lerp(start,end,t);
差不多就是这些,有更深的理解后再来补充,欢迎和我交流。