This question is somewhat unorthodox, I know, but please let me ask it anyway:
What's the formula (or method used) behind Mathf.SmoothDamp()?
I'd totally understand when you guys tell me that it is top secret. The thing is that I need to have something similar outside of Unity and just can't get behind that. I'm not lazy or anything, I'm not asking for finished and working code. I'd only like to get a hint into a useful direction.
You could add another level of smoothing to Magnus Wolffelt's suggestion:
Directly setting the target value: no smoothing, D0 discontinuity (=jump in position f(x)):
myValue=targetValue;
Using simple smoothing: D1 discontinuity (=jump in velocity f'(x), suddenly changing direction):
myValue = Mathf.Lerp(myValue, targetValue, 0.1f);
Using two-level smoothing: D2 discontinuity (=jump in acceleration f''(x) (which is not noticeable, since nature does the same all the time), resulting in linearly changing velocity and therefore smoothly changing position):
While I don't know the exact formula inside that function, you can achieve similar results by a partial Lerp (implement your own if outside unity) every timestep, and save the value of the Lerp:
myValue = Mathf.Lerp(myValue, targetValue, 0.1f);
You should be aware however, that this is not timestep size independent, so if you change the timestep size, you will get different behaviour. Putting the delta time in the t parameter kind of reduces this change, but it will still change the behaviour if you change timestep size.
There is a correct (and slightly complex) way to implement this kind of smoothing to get the same behaviour independent of step size, but I don't have it at hand, and my math skills aren't that great.. :)
I don't know if Unity implements this correctly or not. It is somewhat counter-intuitive that putting deltatime in the t parameter doesn't solve it, so people usually miss this.