skip to content

A third-person character controller catches on stair edges going up and goes briefly airborne on each step going down; how do a step offset and ground snapping fix it?

level: seniorimportance: should knowfreq 46%

answer

  1. a riser looks like a wall
  2. lift, move, put down
  3. pin the character to the tread
  4. not while moving upward

basics

~20 s

Going up, a step-up pass lifts the capsule by the step height, moves it forward and casts back down onto the tread if it is walkable. Going down, ground snapping casts down after each move and pins a grounded character to the surface.

solid answer

~50 s

Going up, the riser reads as a wall to collide-and-slide. A capsule's rounded bottom helps only on small edges: for capsule radius `r` and edge height `h`, the contact normal's up component is `(r - h) / r`, so with `r = 0.4` m and `h = 0.2` m it is 0.5, a 60-degree contact, steeper than a 45-degree limit. The **step offset** fix runs a second attempt: cast up by the step height, cast forward by the move, cast down by the step height plus a margin, and keep that result only if it lands on walkable ground. Going down, horizontal motion carries the capsule off each edge, so it is airborne until gravity catches up. **Ground snapping**: if the character was grounded last step and is not moving upward, cast down by a snap distance at least the step height and, on a walkable hit, move it down and keep it grounded.

go deeper

for a junior

Recall that a step offset lets a character walk up small edges and that ground snapping keeps it on the ground when walking down steps or slopes.

for a middle

Explain the up, forward, down sweeps of a step-up and the conditions for snapping: grounded last step, not rising, walkable hit within the snap distance.

for a senior

Diagnose stair bugs from symptoms: compute when an edge reads as a wall for a given radius, reject tilted edge normals, and stop snapping from eating jumps or ledge falls.

for a principal

Decide with level design whether stairs get ramp colliders or true step-up handling, and fix step height, slope limit and capsule size as shared level metrics.

## Why stairs break a plain controller A **kinematic character controller** using collide-and-slide classifies every hit by its normal: walkable ground if the normal is close enough to up, a wall otherwise. Stairs defeat this classification in both directions. **Going up**, the character hits the **riser**, the vertical face of each step. A box-shaped collider meets it with a horizontal normal, a wall. A capsule fares a little better, because its rounded bottom touches the step's **edge**, and the contact normal then points from the edge towards the centre of the bottom hemisphere. With capsule radius `r` and the edge at height `h` above the capsule's lowest point, that normal's up component is `(r - h) / r`: | Radius `r` | Edge height `h` | Up component | Contact angle | Against a 45 degree limit | |---|---|---|---|---| | 0.4 m | 0.10 m | 0.75 | about 41 degrees | walkable, rides over | | 0.4 m | 0.20 m | 0.50 | 60 degrees | wall, snags | | 0.4 m | 0.30 m | 0.25 | about 76 degrees | wall, snags | So a capsule rides over small edges but snags on real stairs (the figures are this example's, not a standard). **Going down**, horizontal motion carries the capsule past each edge into the air. Gravity takes a few steps to bring it down onto the next tread, so the character briefly reports **airborne**: the fall animation flickers, a jump pressed at that moment is refused, and fall damage or landing effects may fire. ## Step-up: the step offset The **step offset** (or step height) is the tallest edge the character may walk up. When the normal slide is blocked by a wall-like hit near the feet, the controller tries a second path: 1. **Up**: sweep the capsule upward by the step height, stopping early under a low ceiling. 2. **Forward**: sweep it along the blocked horizontal move from that raised position. 3. **Down**: sweep it downward by the distance actually raised plus a small margin. 4. **Accept or reject**: keep the stepped result only if the downward sweep lands on **walkable** ground and the character made more horizontal progress than the plain slide did; otherwise discard it and keep the plain slide. Two details matter. The ground normal should come from the **face** under the character, not from the edge contact the down sweep may report, because an edge normal is tilted; a short raycast at the landing point reads the face. And the step-up must not run when the character is airborne and rising, or it climbs walls mid-jump. ## Step-down: ground snapping **Ground snapping** keeps a walking character glued to the ground when the ground drops away: - run it only if the character was **grounded last step** and is **not moving upward** (a jump or a launch pad must leave the ground); - after the move, sweep the capsule down by a **snap distance**, at least the step height; - if the sweep hits **walkable** ground within that distance, move the capsule down onto it and keep it grounded; - if it finds nothing, or a surface too steep, the character really has walked off a ledge and becomes airborne. Snapping also fixes the downhill version of the same bug: on a slope, horizontal motion lifts off the surface every step, and snapping pulls it back. ## Related fixes and traps - **Ramp colliders on stairs.** Many levels give staircases an invisible ramp collider for characters while the visible steps stay for rendering. The controller then treats the stairs as a slope, which is smoother and cheaper, at the cost of feet that do not match the treads unless animation adjusts them. - **Launching off the top.** If the slid or stepped vertical displacement is written back into the character's vertical velocity, it keeps rising after the last step. Vertical velocity should come from gameplay (gravity, jumps), not from the slide. - **Snap distance too large.** A snap distance bigger than the steps lets characters teleport down short ledges that should be falls. - **Step offset bigger than the capsule allows.** Letting the character step onto edges higher than its radius invites it onto railings and crate tops designers did not intend; the step height belongs in the level metrics designers build to.

  • Why does the down sweep of a step-up sometimes report a tilted normal on a flat tread?
    The capsule's rounded bottom can land touching the tread's edge, and a sweep reports the normal of that edge contact, which tilts towards the riser. Reading the face with a short raycast just inside the landing point gives the tread's true normal for the walkability test.
  • How should ground snapping interact with a jump?
    Snapping must be skipped whenever the character's vertical velocity is upward, at least for the step the jump starts. Otherwise the downward sweep immediately finds the ground the character just left and pins it back, so the jump never happens.
  • Why not just make the capsule radius large enough to ride over stairs?
    The ride-over threshold depends on the radius, so a 0.2 m step would need a radius around 0.68 m for a 45-degree limit. That widens the character, so it no longer fits through doors and corridors built to the level metrics. A step-up pass fixes stairs without changing the body's size.

  • A capsule's rounded bottom rides over any edge below its radius
  • Ground snapping should run while the character is jumping
  • A larger snap distance is always safer
  • The edge normal from a sweep is the tread's normal
  • Stair snagging is fixed by lowering surface friction