So I'm not looking for anything realistic like a physics engine, just want to say that first. I'm working on a simple top-down game and I'm trying to get friction working with deltaTime.
This was my old code:
friction = Math.pow(0.99f, deltaTime * maxFPS);
This worked well and I applied the friction each frame. However, I need to refactor this code since I do not know what the possible maxFPS will be (it could be 30, 60, 120 - it depends on the device limitations).
So here's my new code:
friction = Math.pow(0.6f, deltaTime);
This eliminates the need to know the maxFPS and gives me (roughly) the same output value to apply each frame.
My issue is this: I do not just set the friction to a static value, it changes depending on other factors.
So with my old code, for example, the value I would raise to a power to get friction would range anywhere from 0.6f to 1.0f.
With the new code, I have to use different values since the power is different, so the new range would be 0.0000000000001f to 1.0f.
This just doesn't seem (and feel, when playing the game) right. The range is way too big and from 0.2 - 1.0f the results are all nearly the same value (0.98+, very "slippery" friction) - it doesn't seem like a linear gradient (if that makes sense) the way 0.6f - 1.0f with my old method was.
Just wondering what the common method is to implement frame-independent friction, if I'm doing it right and if there is anything I can do to get the same "feel" I was getting before.
friction
into a force or a velocity change? Formulas likeMath.pow(0.6f, deltaTime)
can be correct but it all depends on how friction is applied. \$\endgroup\$