Skip to content

fix: spin up and lock vehicle wheels from engine and brake - #1076

Open
tomo0613 wants to merge 1 commit into
dimforge:masterfrom
tomo0613:fix/vehicle-wheel-free-spin-and-lock
Open

tomo0613 wants to merge 1 commit into
dimforge:masterfrom
tomo0613:fix/vehicle-wheel-free-spin-and-lock

Conversation

@tomo0613

@tomo0613 tomo0613 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #950: #980 merged the rolling-direction fix (#925) and the skid clamp (#946), but the two other behaviours from #950 are still missing.

  • Free spin: a wheel with engine force doesn't spin up while airborne. It keeps coasting from its last ground speed, and the 0.99 damping even slows it down while the throttle is held. It also doesn't spin faster than the ground when it loses grip under power (burnout).
  • Wheel lock: a braked wheel keeps rolling at ground speed while the vehicle skids, so it never visually locks.

#950 handled these with cannon-es' approach: a new free_spin_speed tuning parameter, and locking whenever brake > engine_force. That approach locked the wheel during any gentle braking. This PR derives both behaviours from the existing engine and brake impulses instead, with no new field or constant.

Approach

Each wheel's spin is driven by the engine and brake impulses acting on its share of the chassis mass (chassis.mass() / num_wheels). That is the same response the engine force has on the vehicle while the wheel has traction, so the spin stays continuous when the wheel leaves the ground, loses grip, or lands. The previous step's spin speed is recovered from the existing delta_rotation.

Wheel state Spin (tire surface speed)
In contact, full traction (skid_info == 1) ground speed (unchanged)
In contact, slipping, engine_force != 0 previous spin + (engine impulse − transmitted forward_impulse) / mass, never slower than the ground
In contact, skidding, brake != 0 previous spin slowed by (brake − transmitted forward_impulse) / mass toward zero, never faster than the ground
Airborne, engine_force != 0 previous spin + engine impulse / mass
Airborne, braking previous spin slowed by brake / mass toward zero

As in update_friction, the brake only acts when engine_force == 0, and it is treated as a per-step impulse. The 0.99 free-spin damping now applies only when the engine isn't driving the wheel. Otherwise it caps the airborne spin at ~99× the per-step spin-up, so a wheel that leaves the ground at speed spins down under throttle.

Gentle braking (within the friction circle) keeps the wheel rolling with the ground. Only an actual skid locks it.

Tests

crates/rapier3d/tests/vehicle_wheel_free_spin.rs:

  • airborne_wheels_spin_up_under_engine_force: spin keeps increasing under throttle, reverses with the engine force, and decays when the throttle is released.
  • wheels_spin_faster_than_the_ground_on_burnout
  • airborne_brake_stops_the_wheel_spin
  • hard_braking_locks_the_wheels_while_sliding: wheels stop rotating while the chassis still slides.
  • gentle_braking_keeps_the_wheels_rolling

The existing issue_925_wheel_rotation and issue_946_vehicle_braking_friction tests still pass. I also tested the change through the TypeScript bindings (a locally built rapier3d-compat) in a three.js driving game.

`Wheel::rotation` only followed the ground speed: an airborne wheel kept
coasting (and slowed down even under throttle), a wheel slipping under
power didn't spin faster than the ground, and a braked wheel kept rolling
while the vehicle skidded.

The wheel spin is now driven by the engine and brake impulses acting on the
wheel's share of the chassis mass, the same response the engine has on the
vehicle while it has traction, so no new tuning parameter is needed:
- airborne: the engine impulse spins the wheel up, the brake impulse slows
  it down to a stop;
- slipping under power: the part of the engine impulse the friction circle
  didn't transmit spins the wheel faster than the ground;
- skidding under braking: the part of the brake impulse not countered by the
  ground friction slows the wheel down until it locks;
- otherwise the wheel rolls with the ground, so gentle braking doesn't lock it.

The free-spin damping no longer applies while the engine drives the wheel.

Follow-up to dimforge#950.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant