Why does a steering agent using seek overshoot and orbit its destination, and how does arrive with a slowing radius fix it?
answer
- seek always wants full speed
- ramp desired speed down to zero
- stopping distance grows with speed squared
- braking distance sets the radius
- a stop radius ends the approach
basics
~20 sSeek always asks for full speed toward the target, so the agent arrives fast and cannot brake in time. Arrive ramps the desired speed down to zero inside a slowing radius, which must be at least the agent's braking distance.
solid answer
~50 sSeek's desired speed is always `maxSpeed`, so the agent crosses the target at speed, the desired direction flips, and the force cap lets it turn back only gradually: it swings past, returns and, with any sideways drift, orbits. **Arrive** keeps seek's direction but, inside a slowing radius `r`, sets desired speed to `maxSpeed * d / r`, with `d` the remaining distance. The radius has to fit the agent's braking: tracking that ramp gives speed `v = (maxSpeed / r) * d`, and since `d` shrinks at rate `v`, the deceleration needed is `(maxSpeed / r) * v`, largest at the edge, `maxSpeed^2 / r`. With maximum deceleration `aMax`, the ramp works only if `r >= maxSpeed^2 / aMax`, twice the constant-deceleration stopping distance. A linear ramp only approaches asymptotically, so add a small stop radius, and cap desired speed at `d / dt` so one long frame cannot step past.
code
pseudocode · 13 linesfunction arrive(agent, target, slowRadius, stopRadius, timeToTarget, dt):
toTarget = target - agent.position
d = length(toTarget)
if d <= stopRadius:
desired = (0, 0)
else:
speed = agent.maxSpeed
if d < slowRadius:
speed = agent.maxSpeed * d / slowRadius
speed = min(speed, d / dt) // never plan a step past the target
desired = (toTarget / d) * speed
steering = (desired - agent.velocity) / timeToTarget
return truncate(steering, agent.maxAcceleration)go deeper
Recall that seek never slows down and that arrive scales the desired speed by distance inside a slowing radius, reaching zero at the target.
Derive why the slowing radius must be at least vMax squared over the maximum deceleration, and explain the stop radius and the per-step speed cap.
Diagnose overshoot from a speed-versus-distance plot, separate tuning errors from frame-time spikes, and pick the speed profile that fits the agent's handling.
Treat speed profiles as a shared feel standard across agent types, so animation and design tune one set of limits instead of patching each overshoot.
## Why seek cannot stop Seek's desired velocity has a fixed length, the maximum speed, however close the target is. Far away that is exactly right. Near the target it causes the classic defect: - The agent reaches the target at full speed. - Once it passes over the point, the desired direction flips by 180 degrees in a single tick. - The force cap lets the velocity bend only gradually, so the agent shoots past, turns, comes back at speed and passes again. - Any sideways component turns that back-and-forth into a loop: the agent **orbits** its destination. Raising the maximum speed makes the loops wider. Raising the force cap hides the problem by allowing near-instant reversals, which look like a cursor rather than a body. ## The arrive behaviour **Arrive** keeps seek's direction and adds a speed profile. Each tick: 1. Compute the remaining distance `d` to the target. 2. If `d` is inside a small **stop radius**, the desired velocity is zero. 3. If `d` is inside the **slowing radius** `r`, the desired speed is `maxSpeed * d / r`; otherwise it is `maxSpeed`. 4. The desired velocity is the unit direction to the target times that speed. 5. The steering acceleration is `(desired - velocity) / timeToTarget`, truncated to the agent's maximum acceleration. The division by a short **time-to-target** makes the agent close most of the velocity error within that time; some formulations, including the original one, use the plain difference as the force and truncate it. ## Sizing the slowing radius The radius is not a free style knob. It has to be large enough for the agent to follow the ramp. Suppose the agent tracks the linear ramp exactly, so its speed is `v = (vMax / r) * d`. The distance shrinks at the rate of the speed, `dd/dt = -v`, so `dv/dt = (vMax / r) * dd/dt = -(vMax / r) * v` The deceleration is largest when the speed is largest, at the moment the agent enters the radius at `vMax`: it needs `vMax^2 / r`. If the agent can decelerate at most `aMax`, the ramp is trackable only when `r >= vMax^2 / aMax`. For an agent with a top speed of 6 m/s and a maximum deceleration of 12 m/s^2, that is a slowing radius of at least 3 m. | Speed profile inside the radius | Peak deceleration needed | Smallest workable radius | |---|---|---| | Linear ramp, `v = vMax * d / r` | `vMax^2 / r`, at the edge | `vMax^2 / aMax` | | Constant deceleration, `v = sqrt(2 * aMax * d)` | `aMax`, throughout | `vMax^2 / (2 * aMax)` | | No profile (plain seek) | none requested | none; it overshoots | For the same 6 m/s agent, the constant-deceleration profile starts braking at 1.5 m. It stops later and more crisply; the linear ramp settles more softly. Which one feels right is a design call, but both must respect the agent's braking. ## Getting the last centimetres right - The linear ramp makes the gap decay **exponentially**: speed falls in proportion to the remaining distance, so the agent creeps forever. A stop radius where the desired velocity becomes zero ends the approach. - A long frame can carry the agent past the point in one step. Capping the desired speed at `d / dt` keeps one step from overshooting. - The real controller lags the ramp by roughly the time-to-target, so leave margin above the minimum radius. - Frame-time spikes amplify every overshoot; a fixed steering step keeps the behaviour consistent across frame rates. ## Arrive along a route Use arrive only where the agent must actually stop, usually the final waypoint. At intermediate waypoints, seeking or path following keeps the speed up; arriving at each one produces stop-start motion. Where a turn is too sharp for the turning radius at full speed, limit the speed before the corner instead of coming to a halt. ## A debugging checklist 1. Plot speed against distance over the last few metres of an approach. 2. Compare the slowing radius with `vMax^2 / aMax` for that agent's limits. 3. Confirm a stop radius exists and zeroes the velocity. 4. Check whether the overshoots line up with frame-time spikes.
- Why can an agent still overshoot slightly when the slowing radius is at least vMax^2 / aMax?That bound assumes the agent tracks the ramp exactly. A real controller closes the velocity error over its time-to-target, so the speed lags the ramp, and discrete steps add a little more. Leave margin above the bound, cap the desired speed at the remaining distance divided by the step, and end with a stop radius that zeroes the velocity.
- How would you make arrive feel snappier without bringing back the overshoot?Use a constant-deceleration profile, desired speed `min(vMax, sqrt(2 * a * d))`, with `a` a little below the agent's real braking limit. It holds full speed longer and brakes as hard as the agent can manage, so the approach is shorter yet still trackable. Shortening the time-to-target also tightens tracking, at the price of saturating the acceleration cap more often.
A driver approaching a stop line has to start braking at a distance that grows with the square of speed: double the speed and the braking must begin four times as far back. Arrive's slowing radius is that braking point, and seek is a driver who never brakes.
- Arrive works with any slowing radius; a smaller one just makes the stop crisper.
- Seek already slows down near its target because the distance shrinks.
- Raising maximum speed fixes orbiting because the agent reaches the point sooner.
- A linear speed ramp brings the agent to an exact stop in finite time on its own.
- Arrive should be used at every waypoint along a route.