Mathf.SmoothDamp not calculating as expected

Hi,
It appears that I have come unstuck with the infamous unity scripting documentation.

Either this is a bug, or I am really not understanding the documentation:

If I call this method with the following:

float newValue = Mathf.SmoothDamp(0f, 1f, ref yVelocity, 2.5f);

Variable newValue is assigned a value of 8+.

What is throwing me here is the documentation in all its ambiguity, claiming the 4th param to be of type float and representing time. If 0.3f represents 300 milliseconds, 2.5f should equal 2500 milliseconds correct?

Any help would be much appreciated.

Cheers

Usually the result should certainly be within the current value (0f) and the target value (1f). The time is used to adjust the velocity, such that the target value is reached within approximately this amount of time. The velocity itself is also important. Which value are you using for the velocity?
Usually, if you want to start smooth, you should have an initial velocity of 0 and then let SmoothDamp take care of it.

1 Like

Thank you for your quick reply Dantus - much appreciated.

I restarted and applied a clamp to velocity before the method call of 0f. I was getting a leak in there only some of the time. That fixes that, but time parameter still appears to be causing me issues.

In my head (logically speaking), I would need to reduce the target time each time the update is accessed, else the smooth variable will never reach the target?

I am using a stopwatch between the updates and subtracting the elapsed time from the target time in order to bring that in, but the result is always that the smoothing reaches the original target in only a few hundred milliseconds. Any thoughts on that?

Cheers

Dantus, this little bit on the end of your reply was the issue. I needed to store the ref out velocity and submit it each time to the method call as an update. Champion - thank you so much.

How do I mark your answer as correct? I don’t see an option to do that?

EDIT: For anyone else reading this post, It should also be noted that TIME is not a constant when using this method. You need to subtract the elapsed time, each time you call the method until you reach your target time.