onephysicsCookbook
onephysics cookbook
Short recipes for common OnePhysics tasks, each with complete code you can copy.
Recipes
Rollback and resimulationBuild a rollback loop with OnePhysics: a ring of snapshots, a late input that rewinds five frames, quiet resimulation, and a check that the result equals a world that had the input on time.Events and sensorsReact to collisions, impacts, sleep and sensor overlaps in OnePhysics, with handlers or polled events, in an order that is the same on every machine.Queries and layersDecide which bodies collide with layers in OnePhysics, then ask the world what is where: a raycast, an overlap test filtered to one layer, and a circle cast that skips chosen bodies.Joints: a chain and a springConnect bodies with OnePhysics joints: a five-link chain hinged to a fixed anchor, and a box hung from a spring.The 3D preview: rigid bodies and clothTry OnePhysics’s 3D engine: a sphere dropped on a box, and a cloth draped over a block, with a snapshot and a world hash like the 2D engine’s.