Readonlyonfires when a breakable constraint passes its maxStretch; it is already removed from the world
Readonlyonfires once per new contact between two bodies, with the bodies of the pair
how far into the next fixed step the clock is, 0 to 1, for interpolated drawing
a box centred on (x, y)
joins two bodies, or a body to a fixed point in the world when b is a point
removes a body (with its joints), or a constraint, from the simulation
How far a constraint is stretched past its rest length, as a fraction of it (0.1 is 10% longer); for a zero-length joint, the distance between its ends. Negative when compressed.
Advances the simulation by dt seconds of real time, running as many fixed steps as that
covers; call it from Scene.update(dt).
how many fixed steps ran
Rigid bodies and constraints in plain TypeScript, stepped on a fixed clock.
The framework side of game physics in a mwg game: it owns the solver, steps it with a
FixedStepperso the simulation is the same at any display refresh rate, and reports contacts through aSignal, while leaving the bodies themselves as plain objects a game readspositionandanglefrom to place its sprites. It is renderer-free, so a game's headless tests can run the same world. No third-party engine: semi-implicit Euler, impulse contacts with restitution and Coulomb friction, and projected distance joints.Bodies never spin:
anglestays where a game puts it (a display offset), collisions use the unrotated shape, and joints rotate their attachment points by it. Circles and axis-aligned boxes collide with each other in every pairing; that is the whole shape catalogue, by design rather than by omission - a game needing polygons brings its own.Constraints are springs and rods. Give one a
maxStretchand it breaks when pulled that far past its rest length (onBreak); a game with a different stress rule readsstretchOfitself and callsremove.Example