Vector3.Lerp HELP!!!

Hi everyone,
I want to make this thing:

  • use vector3.lerp to move an object
  • When the movement is completed, use another time vector3.lerp to move again the same object towards another target.

My question is:

How I can code: “When the movement is completed” using vector3.lerp ??

Thank you to everyone!!!

You can check the Vector3.Magnitude between your object and its destination, if it’s smaller than a “stoppingDistance” variable that you set, tell it to move to the next destination.

public Transform movementObject; //Assign this in the inspector

public Transform targetObject; //Assign this in the inspector

void Update() {
 movementObject.position = Vector3.Lerp(movementObject.position, targetObject.position, Time.deltaTime);
 if((targetObject.position - movementObject.position).magnitude < 1f)) {
  Debug.Log("Finished lerp!");
 }
}

Note: untested code

Use a coroutine, such as MoveObject.

var objects : Transform[];

function Start () {
	yield MoveObject.use.Translation (transform, objects[0].position, objects[1].position, 2.0, MoveType.Speed);
	yield MoveObject.use.Translation (transform, objects[1].position, objects[2].position, 2.0, MoveType.Speed);
}

–Eric

Thank you guys!!!