Planning as a moving window — never the whole trip, always the next stretch
The car below follows the grey road past two obstacles. It has no route memorized. At every single step it imagines a short trajectory (the white dashed line — its current best plan), drives one step of it, then re-imagines from wherever it actually is. The gold trail is what really got driven; the dashed line is a plan that is constantly being thrown away. Slide the horizon and watch the imagination window stretch and shrink while the car keeps driving.
The planner is a real random-shooting MPC running in your browser: 79 candidate steering sequences are rolled out through the car's physics every step, scored on road-distance, obstacle hits and progress, and the winner's first action is executed.
Inside one heartbeat — 79 futures in, one steering command out
Freeze time and look inside a single planning step. Press sample futures: the planner rolls 79 candidate steering sequences through its physics model — the grey fan. Each gets a cost (off-road distance + obstacle penalties − progress). The green trajectory is the cheapest. Now press execute first action: the car moves one step along the winner (thick gold segment) — and the other 99% of the plan, including the rest of the green line, is discarded and re-sampled from scratch.
Costs are computed live from the rollouts — lower is better. This sampling flavor of MPC (random shooting / MPPI-style) is exactly what many model-based RL agents use for control.
Shove it — why replanning beats the perfect plan
Two identical cars follow the same road. The gold car runs MPC, replanning every step. The red car planned once at the start — a flawless open-loop script of steering commands — and executes it blindly. While they drive, hit push: both cars get knocked sideways by the same shove. Watch what each does next. MPC never even notices it was disturbed — it just replans from the new position, like it does every step anyway. The red car keeps executing a plan for a world that no longer exists.
The red car's script was produced by the very same planner — it is not a strawman. The only difference is when planning happens: once, versus every step.
The cul-de-sac — when the window is too short to see the trap
The goal is the green dot. Straight ahead lies a dead-end pocket — a wall shaped like a bracket, open toward the car. A short-horizon planner only scores where it ends up a few steps from now, and every step into the pocket looks like progress… until the wall. Run it with a short horizon and watch the car dive in, panic at the cap, U-turn, exit — and dive right back in, forever. Then lengthen the horizon until the rollouts are long enough to reach the back wall in imagination, and the detour around suddenly scores best.
Nothing else changes between the two runs — same cost function, same candidates, same physics. Only how far the imagination reaches.
The price of foresight — compute explodes, and your model lies more the further it looks
So just crank the horizon to 1000? Two things stop you. One: every extra step multiplies rollout compute — watch the meter. Two: the planner imagines with a model, and models are wrong. Here the model misjudges steering strength and doesn't know about a crosswind. The white dashed line is what it imagines will happen; the red line is what actually happens if you execute that whole plan open-loop — they peel apart, and the error compounds with every imagined step. The gold line is MPC executing one step and replanning: the same wrong model, kept honest by constant contact with reality.
The compute figure counts real rollout steps this page just simulated (79 candidates × horizon). Our sampler's cost grows linearly, but with a fixed sample budget a longer horizon searches an exponentially bigger action space ever more sparsely — real trajectory optimizers pay far more than linear.