# How to calculate object speed so it accelerates exponentially?

Think a rocket or a missile. Completely don't know how to make it start slow and then get progressively faster in an non-linear fashion, given max speed and base acceleration. Curve like this would look best.

 ^                       .
S|                       .
|                      .
|                    ..
|                ....
|         .......
| ........
+------------------------>
T

• A rocket accelerating is not exponential, it is quadratic. Also speed would start at 0 and then grow linearly. Commented Jun 28, 2018 at 14:07
• Possible duplicate of Frame-rate independant movement with acceleration Commented Jun 28, 2018 at 16:05

considering time step dt, position x, speed s, acceleration rate a(s) :

s += a(s) * dt;
x += s * dt;


Acceleration rate a(s) can be a constant, then you will have quadratic acceleration.

For exponential :

a(s) = s * factor


if factor is positive, the more the speed, the more the acceleration.

You can give a few tries for the a(s) function until you come to what looks nice to you...

• @Kromster I do not really understand what you mean. dt is measured by a clock in the game loop to fit the actual elapsed time between last and current iteration. That way time evolution in the game feels real. Commented Jun 29, 2018 at 9:10
• Lets assume acceleration = 1 and compare 0.5sec of game time with one tick where dt=0.5 and five ticks where dt=0.1 correspondingly. In first case, end result will be x = 0.25, but in second x = 0.15. With inconsistent dt results will be unpredictably different. Commented Jun 29, 2018 at 10:20
• Yes you are right. Usually dtis rather small. I am not sure but I would say that as dtgets smaller, the behavior is less sensitive to the variations of dt. I think the OP is more looking for a nice animated behavior than for an actual true physics simulation. But if one looks for an accurate simulation, then it would be good to take the corrections you mention into account. Most little games I have developed were fine enough with simple Euler integration as I show in my answer. Commented Jun 29, 2018 at 10:44
• Hence my comment - it would be nice to mention this detail in the answer ) Commented Jun 29, 2018 at 10:46
• @Kromster : I think you have something in your mind. Yet I never took time to analyse precisely the math behind these kinds of correction for step-by-step integration of exponential equations. Maybe you could explain your idea in an other answer ? Commented Jun 29, 2018 at 10:54

Generally, for this "progressively getting faster" behavior to work, you need to have acceleration constant and variable speed. Update speed and objects position each tick (with dt, delta time between this and previous tick) like so:

acceleration := 1; // some constant value
speed := speed + acceleration * dt;
position := position + speed * dt;


To make behavior even more progressive, you can make acceleration to grow over time too:

acceleration_grow := 1; // some constant value
acceleration := acceleration + acceleration_grow * dt;
speed := speed + acceleration * dt;
position := position + speed * dt;


Note that if you have varying dt, then the behavior will vary as well, since every previous step affects next one. E.g. one dt=0.5 update will produce significantly different result than five updates with dt=0.1, despite having the same dt sum.