Using the following code, the object often overshoots its target. I believe variable time steps are to blame. The higher the max speed, the larger the overshoot in absolute terms, though it seems to stay relatively consistent . Often the overshoot is only a pixel or two, but its obvious. I also tried snapping to target when close enough and slow enough, but to work, the within range needs to be high, and is obvious.
Is there an established way to deal with this problem in variable time step games? Ideally, I don't want to stop early, or begin decelerating any sooner than needed, but I wish to respect maximum acceleration/deceleration rates.
//Acceleration and deceleration are equal.
DistanceToStop = (Velocity/Acceleration) * velocity * 0.5;
DirectionToTarget = sign(Target - CurrentPosition);
AccelerationThisTick = Acceleration * dt * DirectionToTarget;
//reverse acceleration direction for brakes
if (distanceToStop >= distancetoTarget)
AccelerationThisTick *= -1;
//Integration (doesn't make a difference between this and Euler - the overshooting //still occurs)
CurrentPosition += (Velocity * dt) + (AccelerationThisTick * dt * 0.5);
Velocity += AccelerationThisTick;