a为起始位置,b未终止位置,t为a到b之间的插值()
返回值为a + (b - a) * t
Linearly interpolates between two vectors.
Interpolates between the vectors a and b by the interpolant t. The parameter t is clamped to the range [0, 1]. This is most commonly used to find a point some fraction of the way along a line between two endpoints (e.g. to move an object gradually between those points). When t = 0 returns a. When t = 1 returns b. When t = 0.5 returns the point midway between a and b.
为防止在Update()方法中调用Vector3.Lerp(),游戏对象在从a向b移动的过程中越走越慢,最后无限接近b,可令
t = 1 / Vector3.Distance(a , b) * Time.deltaTime
若涉及速度和时间
a--->b ,开始时间startTime,当前时间Time.time,速度始终为speed,则
t = (Time.time - startTime) * speed / Vector3.Distance(a,b)