As you can see in the above video, the Cube is moving at a constant speed. How exactly it is working? If you are wondering the same, Let me tell you the logic behind it. What we want is to move the cube at a constant speed to make it linear. Let’s understand it with a simple calculation.
Desired Duration = 3 Seconds
We are increasing t with Time.deltaTime. So for simple calculation let’s assume we are getting 60 FPS in our game.
Time.deltaTime = 1 / 60 = 0.0167 (Time.deltaTime varies each frame, but this is for our understanding).
It means 3 seconds = 180 Frames Total Frames.
Let’s check iteration by iteration.
First Iteration, elapsedTime = 0.0167, Returned value (0.0167 / 3) = 0.0056
Second Iteration, elapsedTime = 0.0334, Returned value (0.0334 / 3) = 0.0111
Third Iteration, elapsedTime = 0.0501, Returned value (0.0501 / 3) = 0.0167
Fourth Iteration, elapsedTime = 0.0668, Returned value (0.0668 / 3) = 0.0223
Fifth Iteration, elapsedTime = 0.0835, Returned value (0.0835 / 3) = 0.0278
So on and so forth till 180 times.
One Eighteenth Iteration, elapsedTime = 3 (0.0167 * 180), Returned value (3/3) = 1
Hope it is clear to you now. Now let’s see the non-linear way to interpolate gameobject.