So I have a fairly simple piece of code
if (barimage.fillAmount < realFillAmount)
barimage.fillAmount = Mathf.SmoothDamp(barimage.fillAmount, realFillAmount, ref changeSpeed, 0, fillSpeedCap);
To make a bar smoothly changing its value. SmoothDamp isn’t really meant to do this job I guess, but that’s not the topic.(I think I will have to just change its value by += valuePerSecond * Time.deltaTime with an overshoot check)
And after setting FPS to different values, I see that more FPS I have, faster the bar changes it’s fill amount. I don’t get it, why? If maxSpeed is really that framerate dependent, its usage is too unpredictable to use outside of FixedUpdate coupled with Time.fixedDeltaTime.
Your smoothTime arg is zero, so I assume you either don’t actually want a SmoothDamp but rather something like MoveTowards, or it’s a mistake. If you don’t actually need the smooth acceleration, use MoveTowards. If you do, then why smoothTime = 0?
Of course smoothDamp’s effect will be somewhat framerate dependent on the numerical level if you are using the default behavior that uses deltaTime, but it should not look and feel different. Obviously this is not the full code, as we can’t see related vars declared, perhaps something is changing the speed value from the outside?
Btw smoothDamp is exaxtly what I would do and do use for this purpose… with a non-zero smoothTime, of course.
So I made it not framerate dependent by multiplying maxSpeed with Time.deltaTime like this
barimage.fillAmount = Mathf.SmoothDamp(barimage.fillAmount, realFillAmount, ref changeSpeed, 0, fillSpeedCap * Time.deltaTime);
Why I had to in the first place, tho? I know that using smoothTime 0 is kinda missing the point of Mathf.SmoothDamp (and frankly stupid ikr), but I fear that my other SmoothDamp functions in the project which use actual positive smoothTime and maxSpeed not multiplied by Time.deltaTime are also letting value change proportionally to FPS. No good.
I did some tests trying to grasp it
So it seems like in SmoothDamp functions maxSpeed is working as intended and as I thought it should work - framerate independent. Unless you set smoothTime = 0, which you are not meant to do. I guess this activate some overshooting fear behaviour at smoothdamp? In that case, it becoming framerate dependent. Less Time.deltaTime is. faster the allowed speed, for some reason. And it seems like you can avoid this dependency by multiplying maxSpeed by that Time.deltaTime making max speed lower. Which does not really makes sense for me, but it seems to somehow work. It’s an unpexpected result for unexpected function usage. Mind boggling.
Well, now I know that as far as I am not setting smoothTime = 0, everything should be fine.