- Home /
Using Time.DeltaTime doesn't result in framerate independence
I'm trying to lerp some items across a certain specified distance over a determined amount of time. I'm using Time.DeltaTime to achieve framerate independence. However, when forcing lag with the help of a very performance intensive function (drops the framerate to a theoretical 10-15fps), my objects move MUCH slower than they should, even though they should move in constant time, independent of framerate (they take about twice as long, 4s instead of 2s).
What's even stranger is that the calculated FPS (1.0f/Time.deltaTime) stays constant (approx. 66 FPS). When I show the time it took for the lerp to finish (adding up the time.deltaTimes), it shows 2 seconds (which is the desired time, however the actual time it took is at least 2x that).
Can anyone help me figure out what's going on?
var startTime = 0.0;
while(startTime < 2.0){
yield;
startTime += Time.deltaTime;
transform.localPosition = Vector3.Lerp(Vector3(0.0,0.0,0.0), Vector3(0.0,10.0,0.0), startTime/2.0);
}
Can you put in some debug.log statements into that while loop and show us the result?
while(startTime < 2.0){
Debug.Log("pre-yield, start time is" + startTime);
yield;
Debug.Log("after yield, start time is + startTime);
Debug.Log("deltatime is "+Time.deltaTime);
startTime += Time.deltaTime;
Debug.Log("startTime is now " + startTime);
transform.localPosition = Vector3.Lerp(Vector3(0.0,0.0,0.0), Vector3(0.0,10.0,0.0), startTime/2.0);
}
Also, I'm not entirely sure what you're trying to do by having the while loop yield and lerp in the while loop. Can you explain what you want/expect to happen?
Answer by Smike · Aug 07, 2013 at 06:05 PM
Ok, it's fixed. Apparently, the Maximum Allowed Timestep was modified. To fix it, I just went to Edit > Project Settings > Time, and then changed the Maximum Allowed Timestep to a high number (in my case: 0.5).