# Frame Rate Independence for Non-Linear Increases

So while working on my game, I decided that I would have a speed variable increase in the fashion

speed += 1/speed;


with the goal being that in the beginning it increases fast and then it increases slow as it gets higher. However this is being called each frame and I need to make it framerate independent, however just scaling it based on time doesn't give the same results throughout. How would I go about creating a framerate independent increase that dampens like this?

• Can you provide some more detail? Is this a vehicle, sprite, etc.? What are the expected numerical limits of speed? – Jon Feb 29 '16 at 2:27

## 1 Answer

I believe this will be a frame rate independent alternative for this type of movement:

speed = Math.log(time + 1) / Math.log(Math.E) + startingSpeed;


This sets speed equal to ln(time + 1) which increases at a rate of 1/time. You want the +1 because ln(t) is negative while t is less than 1 (and greater than zero).

Just have time start at zero and increase it by deltaTime or the equivalent every update.

Also, for the sake of performance you could store the value of Math.log(Math.E) in a variable and use it instead when calculating speed.

• Good idea. But isn't math.log (math.e) just 1? – Will Fisher Feb 29 '16 at 1:32
• @Will No, it's approx. 0.4343. Math.log is log base 10. If math.log were log base e then it would be 1. – Quintin Steiner Feb 29 '16 at 2:36