# How can I manage the deceleration of units so that they arrive on-target?

When I first started trying to set up my air units' movement in my RTS game, I thought it was going to be easy with simple Euler method linear acceleration. This was far from the case as the ship would have to slow to a halt on exactly the target destination, as well as properly compensate after a sharp turn.

How would I decelerate my unit exactly onto the target destination and properly compensate for changed destinations while still factoring in the current velocity in a 2D simulation (Positions and velocity stored in 2D vectors)?

StarCraft 2 does this well, and I'd like to arrive at a similar effect. I want something like shown here. Acceleration can be seen at 0:20. Turning and maintaining momentum can be seen at 1:25. Deceleration can be seen at 1:55. (Find these times in recent comments of the video).

Note: I'm using a lockstep model and frame rate can be either 5 or 10 per second depending on players' computer abilities.

• Given a speed and a deceleration you should be able to find the stopping distance, and fudge the last few frames to make it exact – ratchet freak Jan 9 '15 at 8:24
• I've been using (n * (n-1)) / 2 * Velocity.magnitude for the stopping distance and interpolating the velocity vector down to 0,0 over the length of n frames (based on acceleration). This works pretty well if the ship is going in a straight line and accelerating directly towards the destination but overshoots when a turn happens. I think dealing with turning is my biggest issue. – JPtheK9 Jan 9 '15 at 8:40
• As I know starcraft 2 steering don't deal with turning (and I don't know RTS that does it). Unit moves to any direction without rotation. And when unit has new velocity it rotates to this direction through few frames with some heuristic (for example, divide angle between current direction and target direction by 2). – Kostya Regent Jan 9 '15 at 9:30
• If you are dealing with rotation, you need to define an angular rotation speed and then use something like this: gamedev.stackexchange.com/questions/73046/… – AturSams Jan 9 '15 at 10:17
• I've always found this website a good source for steering behaviours, in your case: red3d.com/cwr/steer/Arrival.html the full paper is available at red3d.com/cwr/papers/1999/gdc99steer.pdf – Daniel Carlsson Jan 9 '15 at 11:40

closing_distance = max_speed * 2;