# Vector3.Lerp() moving in 1 frame

Why does this not work ?

``````var dogOldPos = new Vector3();
var dogNewPos = new Vector3();
dogOldPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.2 + -Camera.main.transform.up * 1.1);
dogNewPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.5 + -Camera.main.transform.up * 1.1);

while (transform.position != dogNewPos){

transform.position = Vector3.Lerp(dogOldPos, dogNewPos, 3);
yield;
}
``````

It just move in 1 frame.

The final parameter of a Lerp is always in the range of 0 to 1. There are two ways that Lerp() is commonly used. The first is a linear movement:

``````var dogOldPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.2 + -Camera.main.transform.up * 1.1);
var dogNewPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.5 + -Camera.main.transform.up * 1.1);

var timer = 0.0;

while (transform.position != dogNewPos){
transform.position = Vector3.Lerp(dogOldPos, dogNewPos, timer / 3.0);
timer += Time.deltaTime;
yield;
}
``````

The use of 3.0 here means it will take 3.0 seconds to make the movement. The second way produces an eased movement:

``````var dogOldPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.2 + -Camera.main.transform.up * 1.1);
var dogNewPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.5 + -Camera.main.transform.up * 1.1);

while (Vector3.distance(transform.position,dogNewPos) > 0.05){
transform.position = Vector3.Lerp(dogOldPos, dogNewPos, 3.0 * Time.deltaTime);
yield;
}

transform.position = dogNewPos;
``````

The ‘0.05’ will need to be adjusted for your situation. The ‘3.0’ is a speed parameter, but it is not directly related to the time of travel. This second version moves the same fraction of the remaining distance towards the goal each frame. Since the distance is shrinking, the same fraction is a decreasing distance. The result is an eased movement. But this method can take a long time to actually reach the goal. It’s like the old question, “If I move half way to may goal each day, how long will it take me to reach the goal?” The answer in pure math is never. For Lerp() it will reach the goal because the comparison of Vector3s is done with a threshold. The Distance() allows you to speed the process as appropriate to your situation.

What you need is this:

``````var dogOldPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.2 + -Camera.main.transform.up * 1.1);
var dogNewPos = (Camera.main.transform.position + Camera.main.transform.forward * 0.5 + -Camera.main.transform.up * 1.1);
var t : float = 0.0;

while (t < 1){
t += Time.deltaTime; // multiply it by speed if you like
transform.position = Vector3.Lerp(dogOldPos, dogNewPos, t);
yield;
}
``````