Skip to content

0006. Physics: in-house arcade physics + Rapier for rigid bodies

  • Status: Accepted (rigid-body part confirmed by the owner 2026-11-29: Rapier 2D + 3D)
  • Date: 2026-11-26
  • Phase: 1 (arcade), 5 (rigid body)

Platformers need arcade physics: AABB vs tilemap, one-way platforms, slopes, coyote time, predictable jump arcs. Rigid-body engines are bad at this (bodies slide, bounce and rotate; tuning a “tight” jump is hard). Later genres need real rigid-body physics in 2D and 3D, plus raycasts, trigger zones, layers and masks.

  • @ludrel/physics-arcade (in-house, Phase 1): fixed-step, deterministic AABB integration with a swept tile collision pass, one-way platforms, 45°/22.5° slopes, collision layers/masks, triggers, raycasts against tiles and AABBs, spatial hash broad phase. Small (target < 10 KB gzip) and fully unit-tested.
  • @ludrel/physics-rapier (Phase 5): Rapier (Rust → WASM, 2D and 3D builds, deterministic mode) behind the same PhysicsWorld interface for collision events, layers, raycasts and triggers.
Option Pros Cons
Matter.js Pure JS, simple 2D only, slower, maintenance pace slow, no determinism guarantees
Planck.js (Box2D port) Proven Box2D behaviour 2D only
Box2D v3 WASM builds Very fast Bindings less mature in JS
Jolt (WASM) for 3D Excellent 3D performance 3D only; would need a second engine for 2D
cannon-es Small Unmaintained-ish, 3D only
Rapier for platformers too One engine Fights the “arcade feel” platformers need

Writing arcade physics is justified: it is small, it is the heart of the side-scroller’s feel, and no library does it well behind a swappable interface. Rapier’s WASM adds ~hundreds of KB and async init; it is only loaded by games that use it.