---
title: "onephysics"
url: https://recursiveai.org/onephysics/
description: "Deterministic rigid-body physics for .NET in C#. The same world state, bit for bit, on every platform, CPU and thread count, with byte-exact snapshots and per-step world hashes for rollback and lockstep. 2D, with a 3D preview. A preview. MIT or Apache-2.0."
---

# onephysics

Deterministic 2D rigid-body physics for .NET: the same world state, bit for bit, on every platform, CPU, vector width and thread count.

A preview, 0.4.0-preview.1. Previews are not bit-compatible with each other, and the 3D engine is marked experimental.

```sh
dotnet add package RecursiveAI.OnePhysics --prerelease
```

- [Getting started](https://recursiveai.org/onephysics/docs/getting-started/)
- [Docs](https://recursiveai.org/onephysics/docs/)
- [Cookbook](https://recursiveai.org/onephysics/cookbook/)
- [GitHub](https://github.com/recursive-ai-oss/onephysics-csharp)
- [NuGet](https://www.nuget.org/packages/RecursiveAI.OnePhysics)

## A quick look

A world, a ball and the ground, stepped with a fixed time step. The snapshot restores bit for bit, and the hash is the same on every machine.

[Getting started](https://recursiveai.org/onephysics/docs/getting-started/)

*Program.cs · C#*

```
var world = new PhysicsWorld2D();
world.AddBox(new Vector2F(20, 1), at: new Vector2D(0, -1), type: BodyType.Static);
var ball = world.AddCircle(0.5f, at: new Vector2D(0, 5));
for (int i = 0; i < 600; i++) world.Step(1f / 60);
byte[] saved = world.Snapshot();
ulong hash = world.ComputeHash();
```

### Shapes and joints

Circles, capsules, rounded polygons, segments and chains; revolute, prismatic, weld, wheel, distance, motor and mouse joints; bullets and continuous collision.

### Rollback-ready

Byte-exact snapshots and restores, a world hash per step, quiet resimulation, and no allocation in steady state after `Warmup`.

### Events and queries

Collision, sensor, sleep and joint-break events in a fixed order, as handlers or polled spans. Raycasts, shape casts and overlaps, with layers and filters.

### Familiar names

One-liners in Unity’s vocabulary for bodies, joints and a character mover, and a mapping table for moving from Unity’s 2D physics.

### Three tiers, one engine

One-liners, definitions and polled events, and a raw tier, each built on the one below. Handles are small structs, and a destroyed one throws an exception that names it.

### 3D, in preview

Rigid bodies, characters, vehicles, ragdolls, buoyancy and soft bodies, deterministic like 2D, behind an experimental marker while their API settles.

## The same hash everywhere

Only IEEE `+ - * /` and square root decide a result, with onemath’s own transcendental functions, fixed-order reductions and constraint coloring. The world hash after N steps is checked to be the same on x64, arm64 and WebAssembly, scalar or SIMD, one thread or all cores. Every 2D scene is within its speed bar at every thread count.

- [Determinism](https://recursiveai.org/onephysics/docs/determinism/)
- [Changelog](https://recursiveai.org/onephysics/docs/changelog/)

## The package

- **RecursiveAI.OnePhysics**: The 2D engine (`Physics2D`), the 3D preview (`Physics3D`, experimental `OPHYS0002`) and the raw tier (`LowLevel`, experimental `OPHYS0001`). Preview, 0.4.0-preview.1.
- **Dependency**: [onemath](https://recursiveai.org/onemath/), for vectors and deterministic math. Nothing else.
- **Previews**: A snapshot, saved game or replay from one preview does not carry to the next.
- **.NET**: .NET 10. NativeAOT, trimming and browser WebAssembly are supported. MIT or Apache-2.0.

## Go further

- [GitHub](https://github.com/recursive-ai-oss/onephysics-csharp)
- [NuGet](https://www.nuget.org/packages/RecursiveAI.OnePhysics)
- [Getting started](https://recursiveai.org/onephysics/docs/getting-started/)
- [All docs](https://recursiveai.org/onephysics/docs/)
- [Cookbook](https://recursiveai.org/onephysics/cookbook/)
- [Rollback](https://recursiveai.org/onephysics/cookbook/rollback/)
- [Coming from Unity](https://recursiveai.org/onephysics/docs/unity-mapping/)
- [Changelog](https://github.com/recursive-ai-oss/onephysics-csharp/blob/v0.4.0-preview.1/CHANGELOG.md)
