- Home /
how are Mathf.SmoothDamp and Mathf.SmoothStep different
What is the difference between these 2 functions and when should they be used (best practices, etc.)?
Links
http://docs.unity3d.com/ScriptReference/Mathf.SmoothDamp.html
http://docs.unity3d.com/ScriptReference/Mathf.SmoothStep.html
Answer by Owen-Reynolds · Jun 23, 2015 at 04:59 PM
The differences are listed right in the manual links you provided. The trick is, of course they do similar things -- they both move you in a non-linear fashion.
But, as it says, SmoothStep takes a 0-1 time percent input, while SmoothDamp takes a speed. One says to go there in 3 seconds, moving at whatever speed that requires. The other says to go at about 2.5M/S, taking as much time as it requires.
Then, of course, SmoothStep says in the description that it takes a while to speed up at the start, while SmoothDamp says it works like a spring (springs are further==faster.) And, SmoothDamp has more ways to tweak it.
But, in the end, they're just math. You can do any of that yourself if you have a little high school pre-calculus.
are there any guidelines related to when should you rather use one function ins$$anonymous$$d of the other? or it is just a matter of preference?
EDIT
probably these guidelines... though i guess it is still a matter of preference
SmoothStep-useful for creating natural-looking animation, fading and other transitions.
SmoothDamp-can be used to smooth any kind of value, positions, colors, scalars.