Let's say my ship's velocity during deacceleration phase is given by:

v(t) = v0 * exp(-k * t)

where v0 is the speed at the time of starting deacceleration and k is arbitrary constant.

My problem is: Is it possible to calculate such k that the ship "stops" (let's say slows to a velocity vf) at the target position given:

  • v0
  • distance to the target d0 ?

Or alternatively: given k calculating a distance at which deacceleration should start?

I'm making a space simulation game where the ship's warp drive needs to accelerate/deaccelerate exponentially. While accelerating to a maximum speed is easy the problem is with deaccelerating so that the ship "stops" at the destination.

Thank you in advance for any help.


The keyword you're looking for is "easing". There are lots of different easing functions that behave and look different but all of them interpolate some variable from A to B given a time T. If your ship is at A and you want it to decelerate until it hits B, you can give it a velocity by, for example, applying this function:

template<class T>
inline T EaseOutExponential(T time, T from, T to, T duration)
    static_assert(std::is_floating_point<T>::value, "<T>: T must be floating point");

    assert(duration != 0);

    return to * (-Pow<T>(2, -10 * time / duration ) + 1) + from;

This isn't "physical", it's just an interpolation. There are lots of other possible functions.


If you accelerate for half the journey and then decelerate at the same rate for the remaining half you will come to a stop at your destination. Did you mean for the velocity to be exponential? That implies a variable acceleration, which is not very realistic. If this is what you intend then just apply the same logic to jerk (which is the derivative of acceleration with respect to time). That would simply involve negating k.

Since you will end up at extremely high speeds if the distance is long it might be worthwhile to lock "warp drive" to an analytical model to prevent floating-point error from building up in a numerical integrator.

  • \$\begingroup\$ I don't accelerate for half the journey. I accelerate until maximum speed then start decelerating while being d0 distance from the target. Both acceleration/deceleration are exponential (it is a space game where linear acceleration/deceleration wouldn't look good due to the speeds/distances involved). I have the question already answered: k = (v0 - vf) / d0 but the problem is this is correct only if dt -> 0 which is obviously not the case in the game where dt = 1/60 so my ship undershoosts/overshoots the target. \$\endgroup\$ – tomi.lee.jones Feb 26 '15 at 14:51
  • \$\begingroup\$ That's where I would suggest incorporating it into an analytical model. You can break it into three parts of the journey - acceleration until the max speed, cruising until close to the target, and then deceleration to a stop. It might be worthwhile to calculate a starting/stopping distance (assuming the same rate of acceleration/deceleration) so that you don't have to integrate for a changing value of k. \$\endgroup\$ – jmegaffin Feb 26 '15 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.