Vector3.Lerp Manual     Reference     Scripting  
Scripting > Runtime Classes > Vector3
Vector3.Lerp

static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3

Description

Linearly interpolates between two vectors.

Interpolates between from and to by amount t.

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.

JavaScript
// Animates the position to move from start to end within one second

var start : Transform;
var end : Transform;
function Update () {
transform.position = Vector3.Lerp(start.position, end.position, Time.time);
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public Transform start;
public Transform end;
void Update() {
transform.position = Vector3.Lerp(start.position, end.position, Time.time);
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

public start as Transform

public end as Transform

def Update():
transform.position = Vector3.Lerp(start.position, end.position, Time.time)

Another Example

JavaScript
// 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);
}

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
public Transform target;
public float smooth = 5.0F;
void Update() {
transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * smooth);
}
}

import UnityEngine
import System.Collections

class example(MonoBehaviour):

public target as Transform

public smooth as single = 5.0F

def Update():
transform.position = Vector3.Lerp(transform.position, target.position, (Time.deltaTime * smooth))