- Home /
Vector3.Lerp
to move an object from point a to point b, I'm using
var start: Transform;
var end: Transform;
function Update () {
transform.position = Vector3.Lerp (start.position, end.position, Time.time);
}
var start: Transform;
var end: Transform;
function Update () {
transform.position = Vector3.Lerp (start.position, end.position, Time.time);
}
but when used with an input more or less like this:
var start: Transform;
var end: Transform;
function Update () {
if (Input.GetButtonDown ("1")) {
transform.position = Vector3.Lerp (start.position, end.position, Time.time);
}
}
the object is in a constant direction ... but the input does not. I'm doing wrong?
Answer by DaveA · Sep 08, 2011 at 10:36 PM
For one, you need to format your code using that 101/010 button above the edit area. Code - Time.time is 'current time' and what you need for Lerp is the fraction of time (from 0 to 1) that has passed. So in your Start routine you can capture Time.time to 'startTime' then in Update do Time.time - startTime which will max out to 1 in 1 second. So multiply that by the intended duration of the movement.