# [Unity3D] Vector3.Lerp(x, y, Time.deltaTime ）What do you mean?

Time：2021-4-20

Recently, I saw some code and found that it would be written like this`Vector3.Lerp(x, y, Time.deltaTime)`, delta time is the time from the last call, it is not [ zero , one ] So what does this interpolation mean?

In fact, this is a linear interpolation of deceleration. Let me give a very simple example. For example, to move the position of the current object from 0 to 100.

``````float currPosition = 0;

void Update() {
float currPosition = ...;
float targetPosition = Vector3.Lerp(currPosition, 100, Time.deltaTime);
// use target position to update
}``````

hypothesis`Time.deltaTime`If it is 0.2, then the progress from 0 to 100 after the first call is 0.2, and the difference is 20,`targetPosition = 20`
In the next call, it is 20 – > 100, the progress is 0.2, and the difference is \$(100 – 20) * 0.2 = 16 \$, so`targetPosition = 20 + 16 = 36`

By analogy, it can be seen that since delta time is a constant value, the starting value and target value will be close to the target value with iteration, so the difference between each step will be smaller and smaller.

``````Iteration start > target delta time step difference the result of the current iteration
0:    0  -> 100,   0.2,       20,       20
1:    20 -> 100,   0.2,       16,       36
2:    36 -> 100,   0.2,       12.8,     48.8
3:    48.8 -> 100, 0.2,       10.2,     59
4:    59 -> 100,   0.2,       8.2,      67.2
5:    ....``````