---
title: "onephysics cookbook"
url: https://recursiveai.org/onephysics/cookbook/
description: "Short recipes for common OnePhysics tasks, each with complete code you can copy."
version: "0.4.0-preview.1"
---

# onephysics cookbook

Short recipes for common OnePhysics tasks, each with complete code you can copy.

## Recipes

- [Rollback and resimulation](https://recursiveai.org/onephysics/cookbook/rollback/index.md): Build 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…
- [Events and sensors](https://recursiveai.org/onephysics/cookbook/events-and-sensors/index.md): React 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 layers](https://recursiveai.org/onephysics/cookbook/queries-and-layers/index.md): Decide 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…
- [Joints: a chain and a spring](https://recursiveai.org/onephysics/cookbook/joints/index.md): Connect 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 cloth](https://recursiveai.org/onephysics/cookbook/3d-preview/index.md): Try 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.
