RecursiveAI.OnePhysics 0.4.0-preview.1

This is a prerelease version of RecursiveAI.OnePhysics.
dotnet add package RecursiveAI.OnePhysics --version 0.4.0-preview.1
                    
NuGet\Install-Package RecursiveAI.OnePhysics -Version 0.4.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RecursiveAI.OnePhysics" Version="0.4.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RecursiveAI.OnePhysics" Version="0.4.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="RecursiveAI.OnePhysics" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RecursiveAI.OnePhysics --version 0.4.0-preview.1
                    
#r "nuget: RecursiveAI.OnePhysics, 0.4.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RecursiveAI.OnePhysics@0.4.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RecursiveAI.OnePhysics&version=0.4.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=RecursiveAI.OnePhysics&version=0.4.0-preview.1&prerelease
                    
Install as a Cake Tool

OnePhysics for .NET

Deterministic 2D rigid-body physics for .NET, written from first principles: the same world state, bit for bit, on every platform, CPU, vector width and thread count. Package RecursiveAI.OnePhysics, built on onemath for its deterministic math.

Status: preview. The 2D engine is the supported surface: circles, capsules, rounded polygons, segments and chains; revolute, prismatic, weld, wheel, distance, motor and mouse joints; bullets and continuous collision; a character mover; layers, filters, sensors, events and queries; byte-exact snapshot and restore; per-step world hashes; debug geometry. The 3D engine (RecursiveAI.OnePhysics.Physics3D) ships as a preview marked [Experimental("OPHYS0002")]: it works and is deterministic, but its API and its results may change between previews. The raw tier (RecursiveAI.OnePhysics.LowLevel) is [Experimental("OPHYS0001")]. Previews are not bit-compatible with each other: a snapshot or replay from one preview does not carry to the next.

Install

dotnet add package RecursiveAI.OnePhysics --prerelease

Targets net10.0; works under NativeAOT, trimming and browser WebAssembly. Its only dependency is RecursiveAI.OneMath.

2D in a minute

using System;
using RecursiveAI.OneMath;               // Vector2F, Vector2D
using RecursiveAI.OnePhysics;            // BodyType, events, exceptions
using RecursiveAI.OnePhysics.Physics2D;  // PhysicsWorld2D, Body, Character

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));
ball.OnCollisionEnter += c => Console.WriteLine($"hit {c.Other} along {c.Normal}");

var player = world.AddCharacter(at: new Vector2D(3, 1));
for (int i = 0; i < 600; i++)
{
    player.Move(new Vector2F(0.05f, -0.1f), 1f / 60);
    world.Step(1f / 60);                        // fixed dt; events fire after the step, in a deterministic order
}
if (world.Raycast(new Vector2D(0, 10), new Vector2F(0, -1), out var hit)) Console.WriteLine(hit.Point);

byte[] saved = world.Snapshot();                // byte-exact; Restore(saved) continues bit for bit
ulong hash = world.ComputeHash();               // the same on every platform

3D, a preview

The 3D world has the same members with 3D math types. Using it raises the experimental diagnostic OPHYS0002 until you acknowledge it:

#pragma warning disable OPHYS0002        // the 3D engine is a preview
using System;
using RecursiveAI.OneMath;               // Vector3F, Vector3D
using RecursiveAI.OnePhysics;            // BodyType, events, exceptions
using RecursiveAI.OnePhysics.Physics3D;  // PhysicsWorld3D, Body, Character

var world = new PhysicsWorld3D();
world.AddBox(new Vector3F(20, 1, 20), at: new Vector3D(0, -1, 0), type: BodyType.Static);
var ball = world.AddSphere(0.5f, at: new Vector3D(0, 5, 0));
ball.OnCollisionEnter += c => Console.WriteLine($"hit {c.Other} along {c.Normal}");

for (int i = 0; i < 300; i++) world.Step(1f / 60);
if (world.Raycast(new Vector3D(0, 10, 0), new Vector3F(0, -1, 0), out var hit)) Console.WriteLine(hit.Point);

byte[] saved = world.Snapshot();
ulong hash = world.ComputeHash();

What you get

  • Deterministic. Only IEEE-exact + - * / and sqrt and our own transcendental functions; fixed-order reductions and constraint coloring. The world hash after N steps is the same on x64, arm64 and WebAssembly, scalar or SIMD, one thread or all cores.
  • Three tiers, one engine. One-liners (world.AddBox(...), body.OnCollisionEnter), definitions and polled events, and a raw tier, each built on the one below.
  • Rollback-ready. Byte-exact Snapshot/TrySnapshot and Restore, ComputeHash per step, SuppressCallbacks for resimulation, allocation-free steady state after Warmup.
  • Handles you can hold. Body, Shape and Joint are small structs; a destroyed one throws a StaleHandleException naming it.
  • Hostile input is refused, with typed errors that name the value and the limit.

Guide

Licence

MIT OR Apache-2.0, at your option. Copyright (c) Recursive AI, LLC. See LICENSE-MIT and LICENSE-APACHE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on RecursiveAI.OnePhysics:

Package Downloads
RecursiveAI.OneGame.Physics

Preview, built on a preview of OnePhysics: the API may change before it is stable. 2D rigid bodies, characters, triggers and ray casts for deterministic simulations on fixed-point positions, stepped by the sim tick, with state that is saved, restored and hashed with the world.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0-preview.1 40 10/30/2026
0.3.0-preview.1 101 10/30/2026
0.2.0-preview.1 117 10/29/2026
0.1.0-preview.6 136 10/29/2026
0.1.0-preview.5 136 10/29/2026

See CHANGELOG.md in the repository.