Problem
Bodies in src/physics are never put to sleep — every dynamic body is integrated and solved every tick regardless of whether it has come to rest. Production 2D physics engines (Box2D, Matter.js, Rapier2D) deactivate bodies whose linear/angular velocity stays below a threshold for a short time, skipping them in integration and the solver until something wakes them (a new contact, an applied force/impulse, a joint update).
Impact
Wasted CPU on scenes with lots of settled bodies (e.g. a pile of boxes at rest, a terrain full of debris) — the engine keeps re-solving contacts and re-integrating bodies that aren't moving.
Suggested fix
- Track per-body linear/angular velocity against a "sleep threshold" over a short time window.
- Mark bodies that stay under threshold as asleep; skip them in the integration and broad/narrow-phase/solver systems.
- Wake a sleeping body when: a new/updated contact touches it, an impulse/force/torque is applied to it, or a connected joint's other body wakes.
- Expose sleep threshold/time and a way to opt a body out of sleeping (e.g. for player-controlled bodies) via the rigid body component options.
Acceptance criteria
Problem
Bodies in
src/physicsare never put to sleep — every dynamic body is integrated and solved every tick regardless of whether it has come to rest. Production 2D physics engines (Box2D, Matter.js, Rapier2D) deactivate bodies whose linear/angular velocity stays below a threshold for a short time, skipping them in integration and the solver until something wakes them (a new contact, an applied force/impulse, a joint update).Impact
Wasted CPU on scenes with lots of settled bodies (e.g. a pile of boxes at rest, a terrain full of debris) — the engine keeps re-solving contacts and re-integrating bodies that aren't moving.
Suggested fix
Acceptance criteria
documentation-site/docs/docs/physics