Vector3.Lerp 插值
static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3
Description描述
Linearly interpolates between two vectors.
兩個向量之間的線性插值。
Interpolates from towards to by amount t.
按照數字t在from到to之間插值。
t is clamped between [0...1]. When t = 0 returns from. When t = 1 returns to. When t = 0.5 returns the average of from and to.
t是夾在 [0...1]之間,當t = 0時,返回from,當t = 1時,返回to。當t = 0.5 返回from和to的平均數。
另一個例子:
// Follows the target position like with a spring //像彈簧一樣跟隨目標物體
var target : Transform;
var smooth = 5.0;
function Update () {
transform.position = Vector3.Lerp (
transform.position, target.position,
Time.deltaTime * smooth);
}
插值的使用很平凡,比如在網絡坐標的傳送中,每間隔一個fixupdate傳送一次的坐標在使用過程中就需要使用到插值的方法達到平滑移動的效果。