A swerve mechanic built around jerk, not steering itself: comfort only drains when the steering command changes sharply frame to frame. Hold a wide, early line around an obstacle and the passenger barely notices. Flinch at the last second and the same dodge that saves the car costs the ride. The two failure states are different games — crash into something you didn’t avoid, or get bailed on by a rider whose comfort ran out from too many panicked last-second corrections, even if you never hit anything.
Timed to the news: Las Vegas opened its streets to thousands of robotaxis this week.
Reuse
The mechanic lives in src/robo-swerve.js as a framework-free ES module:
createSwerveDriver(opts)— returns a state object; callupdate(dt, input)each frame withinput = { steer: -1..1 }.opts:steerAccel,maxLateralSpeed,damping,jerkThreshold,comfortDrainRate,comfortRegenRate,comfortMax.- State exposes
x/vx(lateral position/velocity — the coordinate space and bounds are the caller’s to define and clamp) andcomfort/jerkfor UI/effects. There’s no obstacle model in the mechanic itself; the demo’s spawn/collision/difficulty-ramp logic lives indemo/index.htmlas a reference, not part of the reusable module.
Gotchas
jerkis|Δtarget acceleration| / dt, so it spikes on any abrupt steering reversal even at low speed — tunejerkThresholdto the input method (a keyboard’s instant on/off is jerkier by nature than analog stick input).- The demo in
demo/bundles its own copy of the module (self-contained by contract). If you touchsrc/, re-copy it intodemo/.