How to calculate a coefficient depending on a frame rate?

19 Views Asked by At

I'm developing a game and currently it updates the game world 60 times per second, and I have the following code which works perfectly when the game is updating at that rate:

forceX *= 0.98;
forceY *= 0.98;

However, I would like to change the tick rate to 20 now, but still achieve the same effect. So, I realized that if the game updates 60 updates per second, then that's 3 updates in 50 milliseconds. So if the starting number was 10, then after 50 milliseconds, the result would look like:

10 * 0.98 * 0.98 * 0.98 = 9.41192

Because an update at a 60 tick rate happens every 16.667 milliseconds, so after 16.667 * 3 = 50 milliseconds, the initial value would be 9.41192

Similarly, if the tick rate was 20, then a single update would occur once every 50 milliseconds.

So I would need to do:

10 * x = 9.41192

To get the same result for what the value will be after 50 milliseconds. And in this case x is 0.941192

Which means at a 60 tick rate, the x value is 0.98, and at a 20 tick rate, our x value is 0.941192

My question is, how do we calculate this? That is, can we devise a function, that, given the following inputs, returns the following outputs?

fn(60) = 0.98
fn(20) = 0.941192

If so, how? Sorry if this question is very basic. Math is not my strong suit.