- Home /
Vector3 Lerp = SmoothDeltaTime vs deltaTime
Hello guys, I'm making a movement here, using Vector3.Lerp.
At the end of the line, I was always using Time.deltaTime, but recently, my editor player became very laggy, and the movement too. Then I tried using SmoothDeltaTime, and bam, the movement became way smoother! I didn't noticed any differences in my character speed or the heigh it jumps, so, what's the difference between these two? and why my editor is lagging and my build runs fine?
Also: These results happened in the editor screen only, whats even more strange, is that, when playing on a build, even with the normal Time.deltaTime, my game runs smooth, the problem is running in the editor, everything just lag as hell. ( I have no Debug.Log, i'm not selecting anything on the inspector and my console isn't showing anything, i don't know where the lags come from. The "stats" screen shows around 200fps(2ms). )
Thanks in advance.
Answer by iwaldrop · Dec 16, 2013 at 04:35 AM
Read more info about it here. Basically, it does exactly what it says; it smooths the deltaTime.
Say the frame rate is humming along at 30 fps, then you experience a hiccup of a few frames at 15. DeltaTime will report a difference of 2 ms (30 fps = 2ms / frame, 15 fps = 4ms / frame), but smoothDeltaTime will report something closer to 2ms (but weighted by the frame loss). You can read more about smoothing here.
Thanks, But would you reccomend using smoothDeltaTime over deltaTime? every character controller I see uses deltaTime. Why? smoothDeltaTime looks better. Can smoothDeltaTime give imprecise results as far as movement goes? Thanks.
Well, yes, it will be more imprecise because it's not a true measure of the time between the current frame and the last. I've never used smoothDeltaTime, but I'm sure there are particular cases where it's proper to use.
Additionally, there's probably more work that needs to be done under the hood to generate the smoothDeltaTime (since smoothing needs to occur). Obviously Unity must track some of the data that's required, because it can never be certain when it might be used. But I'd bet that the calculations are actually performed in the getter, so (technically) using it will decrease your framerate that much more.
Well, i tried mixing a few things in my code, in the end, i used Time.deltaTime for the general movement, because as I tought, smoothDetlaTime gave me some strange results sometimes, the character would go throught the wall sometimes, i guess its because it doesnt slow down properly when got closer to the wall due to the imprecise smooth. But it was useful when doing some other calculations, and the framerate haven't suffered as far as I can tell. From now on I will be using the old trial and error to see when its good to use one or another. Thanks for your awsers :)
Your answer