Your problem is pretty underconstrained. I'll suppose that the best solution is to decelerate (i.e. accelerate in the direction opposite to velocity) so that maxVelocity
won't be a problem.
First, find out how many time intervals there will be before the object reaches the target (assuming no acceleration):
var dt = 0.016;
var jumps = distance/(dt * velocity); <-- round DOWN
Then apply some basic physics to travel distance
in that amount of time:
x = vt + at^2/2
a = 2(x-vt)/t^2
acceleration = 2*(distance - velocity*jumps*dt)/(jumps*dt*jumps*dt);
This works pretty well. There's a slight kludge in there that bothers me a little, but I don't feel like tracking down right now-- it probably cancels out a kludge in the code.