Simulation level of detail (LOD) steps distant rigid bodies less often.
dotnet add package RecursiveAI.OnePhysicsRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneMath; using RecursiveAI.OnePhysics; using RecursiveAI.OnePhysics.Physics3D; var world = new PhysicsWorld3D(); var ball = world.AddSphere(0.5f, new Vector3D(100, 10, 0)); world.SetSimulationLod([Vector3D.Zero], [new LodBand(30, 1)], farPeriod: 4); world.Step(1f / 60f); Console.WriteLine( world.Counters.LodIslandsSkipped);
The distant ball’s island (a group of connected bodies) is skipped on the first step.
1Unzip the example, then dotnet run.
The full program
The full program gives two separated balls the same horizontal speed with gravity disabled. The near ball advances every step; the far ball waits for every fourth step. It then moves the focus to the far ball.
using RecursiveAI.OneMath; using RecursiveAI.OnePhysics; using RecursiveAI.OnePhysics.Physics3D; var world = new PhysicsWorld3D(new() { Gravity = default }); var near = world.AddSphere(0.5f, new Vector3D(0, 0, 0)); var far = world.AddSphere(0.5f, new Vector3D(100, 0, 0)); near.LinearVelocity = far.LinearVelocity = new Vector3F(1, 0, 0); world.SetSimulationLod([Vector3D.Zero], [new LodBand(30, 1), new LodBand(80, 2)], farPeriod: 4); Console.WriteLine("Step Near-X Far-X Skipped-islands"); for (int i = 1; i <= 4; i++) { world.Step(1f / 60f); Console.WriteLine($"{i} {near.Position.X:F3} {far.Position.X:F3} {world.Counters.LodIslandsSkipped}"); } world.SetLodFocus([far.Position]); world.Step(1f / 60f); Console.WriteLine($"Focus moved: far X={far.Position.X:F3}");
dotnet run prints:
Step Near-X Far-X Skipped-islands 1 0.017 100.000 1 2 0.033 100.000 1 3 0.050 100.000 1 4 0.067 100.067 0 Focus moved: far X=100.083
LOD periods must be 1, 2, 4 or 8; invalid configuration values throw ArgumentOutOfRangeException.
Variations
Keep a region at full rate. Append this to the snippet at the top. The region overrides distance bands; the next step skips no islands.
world.SetSimulationLod( focusPoints: default, bands: default, farPeriod: 1, regions: [new LodRegion3D(new(90, -10, -10), new(110, 10, 10), 1)]); world.Step(1f / 60f); Console.WriteLine( world.Counters.LodIslandsSkipped);
The added lines print:
0Related recipes
The short answer
Use PhysicsWorld3D.SetSimulationLod to assign stepping periods by distance from focus points, then call SetLodFocus as those points move. A period of 4 means an eligible island advances on every fourth world step using four steps’ worth of time. It is not slow motion: the intended elapsed time remains the same. The world-scale specification defines the schedule and exceptions.
How do I implement physics simulation level of detail in C#?
Start with a full-rate band around the player, wider bands for distant objects and a far period outside all bands. The runnable example uses a 30-meter period-1 band, an 80-meter period-2 band and period 4 beyond them. Keep calling world.Step at your normal fixed interval. The world decides which islands are due; skipping calls to Step yourself would affect everything, including characters and fluids.
An island is a connected group of bodies that must be solved together. Its schedule uses the smallest period of its bodies, so a connected chain cannot be split into near and far clocks. The far ball in the example stays at the same X for three printed steps, then advances on the fourth. LodIslandsSkipped counts skipped islands, not bodies and not elapsed milliseconds.
Regions provide an explicit override. Inside overlapping regions the smallest period wins; outside them, the first distance band that reaches the nearest focus determines the period. If there are no bands or no focus points, distance-based stepping is period 1. The variation shows a full-rate region, useful for an interaction area even when the player is elsewhere.
Where can I find a C# physics simulation LOD example?
The download above is a complete console project using the released NuGet package. No renderer or scene asset is required: two spheres and a printed position table expose the schedule directly. Change the focus after the fourth step and the far ball begins advancing at full rate. In a game, pass the player’s current position instead of the example’s ball position.
Keep bodies driven by external code each step inside period-1 regions. Islands touching kinematic bodies are pinned to period 1 and time scale 1. Islands containing bodies pinned by the engine’s joint schedule, such as vehicles or rope machines, are also kept at full rate. Characters, soft bodies, rods and fluids run in their own full-rate stages regardless of these LOD regions.
A skipped island is temporarily suspended, not permanently put to sleep: contact updates, integration and events wait, and its sleep timers retain their value. A new contact with an awake body can wake a suspended island silently and use the finer period. Crossing a band can shift a body’s clock by up to period - 1 steps without changing its velocity. These rules mean LOD is not a promise of identical trajectories to full-rate stepping. Keep gameplay-sensitive contacts at full rate and use the printed schedule to check that your regions cover them.