Comments and answers for "can someone explain how using Time.deltaTime as 't' in a lerp actually works?"
http://answers.unity.com/questions/14288/cansomeoneexplainhowusingtimedeltatimeasti.html
The latest comments and answers for the question "can someone explain how using Time.deltaTime as 't' in a lerp actually works?"Comment by jjmontes on jjmontes's answer
http://answers.unity.com/comments/1807735/view.html
I think this approach is the only technically correct solution in order to deltaTime inside Lerp or in general to use Lerp for dead reckoning with a variable frame rate. I'll check the math again, though, because we came up with a slightly different expression.Fri, 22 Jan 2021 23:23:27 GMTjjmontesAnswer by thecommentorlord
http://answers.unity.com/answers/1749577/view.html
I have a potentially simpler solution to that of Eric’s involving the “slow down while approaching target” effect (the curvature is slightly different though):
curPos = Vector3.Lerp(curPos, endPos, 1Pow(2, Time.deltaTime * rate));
curPos = current position
endPos = end position
2 = arbitrary, could be anything larger than 1 (changing it does the same thing as changing the rate).
rate = the rate of the movement  higher value means approaching the end position faster.

Here’s an example to prove this works:
For simplicity let’s just assume the positions are real numbers.
curPos = 1 (at the beginning), endPos = 0, rate = 1.
We’ll track curPos over the duration of 1 time unit to determine the final result in two cases:
**1. If Time.deltaTime = 1:**
in this case the calculation will run 1 time:
curPos = Lerp(1, 0, 1Pow(2, 1*1)) = Lerp(1, 0, 0.5) = 0.5;
so the final result is 0.5.
**2. If Time.deltaTime = 0.25:**
in this case the calculation will run 4 times:
curPos = Lerp(1, 0, 1Pow(2, 0.25*1)) = Lerp(1, 0, 0.16) = 0.84;
curPos = Lerp(0.84, 0, 1Pow(2, 0.25*1)) = Lerp(0.84, 0, 0.16) = 0.705;
curPos = Lerp(0.705, 0, 1Pow(2, 0.25*1)) = Lerp(0.705, 0, 0.16) = 0.59;
curPos = Lerp(0.59, 0, 1Pow(2, 0.25*1)) = Lerp(0.59, 0, 0.16) = 0.5;
so the final result is still 0.5, regardless of Time.deltaTime’s value.
The reason this works is actually pretty simple.
Going with the previous example, what we actually did was this:
**1. If Time.deltaTime = 1:** curPos = 1*2^(1)
**2. If Time.deltaTime = 0.25:** curPos = 1*2^(0.25) *2^(0.25) *2^(0.25) *2^(0.25) = 1*2^(0.250.250.250.25) = 1*2^(1)
I hope this can help someone.Mon, 20 Jul 2020 10:03:18 GMTthecommentorlordComment by thecommentorlord on thecommentorlord's answer
http://answers.unity.com/comments/1752470/view.html
@Bunny83 you're right, I got the Lerp backwards. I'm used to multipliers. Fixed it now.
The idea of this solution is that it's a mathematically correct method that can be written in one line. Not the most efficient method, but most of the time it will suffice. I'm sorry this isn't groundbreaking, it's just a useful method I came up with, and I wanted to put it out there in case somebody finds it helpful. Frankly I don't think I will be doing that again if this is the reaction I'm getting.Sat, 18 Jul 2020 18:05:23 GMTthecommentorlordComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1749629/view.html
Sorry but your math is totally broken ^^. You take 2 to a negative power so it's the same as doing one over 2 to the positive power. At the moment when deltaTime gets larger it means the movement should get faster and when deltaTime gets smaller it should get slower. However your code does the opposite.
Your assumption about Lerp is the wrong way around as well. This is not true:
curPos = Lerp(1, 0, Pow(2, 0.25*1)) = Lerp(1, 0, 0.84) = 0.84;
This line does **not** result in 0.84 but in 0.16 since you move 84% of the remaining distance towards the target. So from "1" distance only 0.16 are left over.
<br>
Besides that all your results are wrong, how is that simpler? The Pow function with fractional exponents is one of the most expensive floating point operations. What you probably had in mind was using your calculated factor as multiplier. Though that's not what is happening here.
<br>
When you post a new solution to a 10 years old question it has to be somewhat groundbreaking ^^ At least run some tests inside the actual software with some extreme cases.Thu, 09 Jul 2020 11:17:32 GMTBunny83Comment by meat5000 on meat5000's answer
http://answers.unity.com/comments/1474537/view.html
You shouldn't hardcode that figure at all, but ins$$anonymous$$d make it a variable. It's then a Scale factor.Wed, 28 Feb 2018 10:32:24 GMTmeat5000Answer by astracat111
http://answers.unity.com/answers/1474427/view.html
Hopefully someone reads this part as well because this took me some testing to figure out since I"m such a noob...
If you move an gameObject over frames like this:
currentDistance = (currentFrame / target_Frame);
gameObject_ToMove.transform.position = Vector3.Lerp (startingPosition, targetPosition, currentDistance);
To make it frame independent it's incredibly simple. You just want to add Time.deltaTime onto the end of the current distance like so:
currentDistance = (currentFrame / target_Frame) + (0.01f * Time.deltaTime);
gameObject_ToMove.transform.position = Vector3.Lerp (startingPosition, targetPosition, currentDistance);
The reason I use '0.01f' is because if you just add Time.deltaTime onto the end of your equation alone it will go too fast.Wed, 28 Feb 2018 01:19:16 GMTastracat111Comment by BlueRaja_2014
http://answers.unity.com/comments/892151/view.html
I've written a blogpost to answer this exact question: http://www.blueraja.com/blog/404/howtouseunity3dslinearinterpolationvector3lerpcorrectlyTue, 03 Feb 2015 02:01:23 GMTBlueRaja_2014Comment by cregox on cregox's answer
http://answers.unity.com/comments/581441/view.html
also, check out my answer for another point of view here: http://answers.unity3d.com/questions/14288/cansomeoneexplainhowusingtimedeltatimeasti.html#answer581439Fri, 22 Nov 2013 22:21:33 GMTcregoxAnswer by cregox
http://answers.unity.com/answers/581439/view.html
Eric mentioned the FPS can vary and it will throw unexpected high values for `deltaTime`. I think this deserves more attention.
(1)
In practice, when [I was using][3] `Time.deltaTime` and [Quaternion.Lerp][1] (it's actually irrelevant if it's quaternion or vector3 or whatever lerp) I was getting this [nasty looking error][2]:
CompareApproximately (aScalar, 0.0F)
UnityEngine.Quaternion:Lerp(Quaternion, Quaternion, Single)
This is because, eventually the deltaTime would make it bigger than 1, thus clamping to 1 and, in my code, for the 1st frame only, the destination rotation was a very bad `(0, 0, 0, 0);`. The point here is: both the clamping and the bad value were unexpected, resulting into a little hard to debug error. Mostly because it's hard to reproduce.
The true effect was nothing that makes the lerping noticeable. But this is something to consider for point 2:
(2)
As we can see in (1) there is this extra problem with the *trick* as it will not behave the same every time, precisely because the FPS can vary. **But** it's not that easy to reproduce the *trick* also, because it kind of balances out processor speeds and so it's one of the best tricks to make a Lerp work similarly in different machines.
For instance, a much simpler way to achieve the same **ease out** *trick* effect is to just set a `const`:
transform.rotation = Quaternion.Lerp(originalRotation, targetRotation, 0.1f);
But if you run that on a i7 quad core versus on an iPhone, you'll already see the difference.
**tl;dr**
So, **there is in fact a [good use][4] for `Time.detalTime` on lerping**. You just need to be aware of the caveats!
[1]: http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Lerp.html
[2]: http://forum.unity3d.com/threads/154218QuaternionLerpproblemCompareApproximately(aScalar00F)
[3]: http://answers.unity3d.com/questions/171380/camerarelativefreeorbit.html
[4]: http://wiki.unity3d.com/index.php/MouseOrbitZoomFri, 22 Nov 2013 22:21:10 GMTcregoxComment by Nition on Nition's answer
http://answers.unity.com/comments/385951/view.html
If you want something that just runs e.g. every update ins$$anonymous$$d of in a coroutine, you could do something like:
float change = Time.deltaTime*speed;
if (curVal < targetVal) {
curVal += change;
if (curVal > targetVal) curVal = targetVal;
}
else {
curVal = change;
if (curVal < targetVal) curVal = targetVal;
}
return curVal;
Note that "speed" here is different to "time" above, in that it doesn't refer to any specific amount of time to transition between values.Wed, 23 Jan 2013 02:52:54 GMTNitionComment by SisterKy
http://answers.unity.com/comments/146909/view.html
*crossreference* http://answers.unity3d.com/questions/9757/timetimeexplanation.html Greetz, $$anonymous$$y.Thu, 21 Jul 2011 23:32:52 GMTSisterKyComment by dirdmister on dirdmister's answer
http://answers.unity.com/comments/108173/view.html
im looking to smooth out client player movement~Tue, 29 Mar 2011 20:31:07 GMTdirdmisterComment by dirdmister on dirdmister's answer
http://answers.unity.com/comments/108172/view.html
hi...you say "var rate = 1.0/time;"...if i was not doing this in a function what would time be? just Time.deltaTime?Tue, 29 Mar 2011 20:30:43 GMTdirdmisterComment by Eric5h5 on Eric5h5's answer
http://answers.unity.com/comments/99847/view.html
A problem with this script is that $$anonymous$$oveObject can only be used properly for one object at a time, since "i" and "rate" aren't local to the coroutine.Sat, 05 Feb 2011 13:11:36 GMTEric5h5Answer by Ippokratis
http://answers.unity.com/answers/46350/view.html
<p>Another script based on Eric's, that prevents the jag effect. Thanks to Eric for the original script, the idea of rate is very usefull.</p>
<pre><code>var pointA:Vector3;
var pointB:Vector3;
var time:float = 10.0;
private var i:float = 0.0;
private var rate:float = 0.0;
function Update ()
{
MoveObject(this.transform, pointA, pointB, time);
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float)
{
rate = 1.0/time;
if (i < 1.0)
{
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
}
}
</code></pre>Sat, 05 Feb 2011 10:30:46 GMTIppokratisComment by Tetrad on Tetrad's answer
http://answers.unity.com/comments/73535/view.html
If you want a better way to achieve nearly the same effect as the "trick" example, but have a better way of knowing how long it takes is to just change your lerp to an easing lerp. A decent example is $$anonymous$$athfx.Sinerp, found here: http://www.unifycommunity.com/wiki/index.php?title=$$anonymous$$athfx
You treat it like a normal lerp, but it eases out at the end.Mon, 31 May 2010 22:09:33 GMTTetradComment by rocket5tim on rocket5tim's answer
http://answers.unity.com/comments/73101/view.html
One issue I noticed with the "trick" example, is that the object will visually appear to have reached it's destination, but the while loop is still counting down behind the scenes for a few more milliseconds. This means if you're waiting for the while loop to finish before firing off something else, there's a perceived "lag" from the time your eye sees the object stop until the next thing is triggered. To fix this, I had to add: if(i >= 0.8) break; to break the while loop at the point where I visually see the object has reached its endPos. Is there a better way to do this?Tue, 25 May 2010 22:23:40 GMTrocket5timAnswer by Eric5h5
http://answers.unity.com/answers/14289/view.html
<p>Time.deltaTime is the time since the last frame. In Lerp, the third parameter is a float between 0 and 1. If it's 0, you get the first parameter in Lerp. If it's 1, you get the second. Therefore, with a statement like</p>
<pre><code>transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime);
</code></pre>
<p>in Update, you get a position that's partway between <code>transform.position</code> and <code>target.position</code>, depending on the time difference between the current frame and the last frame.</p>
<p>For example, a Time.deltaTime value of .01 (100fps) would return a value that's a combo of 99% <code>transform.position</code> and 1% <code>target.position</code>. As this is repeated each frame, the <code>transform.position</code>, assuming <code>target.position</code> is stationary, becomes closer and closer to <code>target.position</code> but never <em>quite</em> reaches it. (Unless the framerate drops to 1fps or less, in which case Time.deltaTime would be 1 or greater, so the return value would be 100% <code>target.position</code>.)</p>
<p>Note that this is a "trick" usage of Lerp, which creates a "slow down as you approach the target" effect. It's mathematically incorrect, though, since it will produce results that vary somewhat depending on the framerate. This is better:</p>
<pre><code>function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) : IEnumerator {
var i = 0.0;
var rate = 1.0/time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}
</code></pre>
<p>That's a coroutine that moves a transform from <code>startPos</code> to <code>endPos</code> over a given time. This happens as <code>i</code> advances from 0.0 to 1.0, and results in completely linear movement, without the "slowdown" effect.</p>
<p>As for Time.time, consider</p>
<pre><code>transform.position = Vector3.Lerp(startPos, endPos, Time.time);
</code></pre>
<p>in Update. This moves the transform from <code>startPos</code> to <code>endPos</code> as the time advances from 0.0 to 1.0. Once the time is past one second, no further movement will occur since the third parameter in Lerp is clamped between 0 and 1. Obviously this isn't very useful unless you actually only want movement to happen for the first second of gameplay for some reason.</p>Fri, 02 Apr 2010 10:53:33 GMTEric5h5