Skip to content

07 / Movement

Acceleration & friction

ramp up, coast down

Instead of jumping straight to full speed, the character gains speed at a steady rate while the input is held and loses it to friction when it's released. A short ramp gives movement weight and momentum; a long one makes it feel like ice. Hold Left or Right and compare the dashed stick input with the speed that follows it.

Use it for
  • Platformer and top-down characters
  • Vehicles and anything that should feel heavy

Prompts to paste

Prompt line

Movement feels twitchy because velocity snaps straight to the stick. Make it change at a rate, with dt in every step: give reversals extra braking so turns stay sharp, use gentler rates in mid-air, and aim for about 0.1 s from standing to top speed and a little less to stop.

Full prompt

Change horizontal movement from setting velocity directly to changing it at a rate. Derive an acceleration from a tunable time to top speed (0.12 s) and a deceleration from a time to stop (0.08 s). Each frame, move velocity toward input × maxSpeed by acceleration × dt while input is held, toward 0 by deceleration × dt when it's released, and by 2 × deceleration × dt while the input opposes the current motion. Scale both rates to 60% in the air. Because everything is multiplied by dt, the movement stays the same at any frame rate.

Examples

Nimble hero

Platformer heroes often reach top speed in 0.05–0.15 s: direct, with just a hint of momentum.

Heavy machine

A mech or truck can take 0.3–0.5 s to get going, which reads as mass. Give it strong brakes so it stays controllable.

Quick turnarounds

Braking harder when the input reverses lets the character change direction fast without making normal stops slippery.

Pitfalls

A fixed lerp factor per frame

lerp(velocity, target, 0.1) every frame moves differently at 30 and 144 fps. Use rates multiplied by dt.

Full control in the air

Ground-level grip in mid-air makes jumps feel floaty. Lower the rates while airborne.

Friction while pushing

Applying friction even while the input is held can stop the character from ever reaching top speed.

Starting values

SettingValueNote
Time to top speed0.05–0.25 s
Time to stop0.05–0.15 s
Turnaround braking1.5–3× the normal rate
Air control50–80% of the ground rates