---
title: "Make a 2D physics slow-motion zone in C#"
url: https://recursiveai.org/onephysics/cookbook/slow-physics-in-a-region/
description: "Create a 2D slow-motion zone with OnePhysics in C#. Compare pendulum periods with and without the zone while keeping the same physics timestep."
version: "1.0.0"
---

# Make a 2D physics slow-motion zone in C#

**OnePhysics** is a free, open-source physics library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePhysics) · [GitHub](https://github.com/recursive-ai-oss/onephysics-csharp) · [Docs](https://recursiveai.org/onephysics/docs/) · [Download example (.zip)](https://recursiveai.org/onephysics/cookbook/slow-physics-in-a-region/slow-physics-in-a-region.zip)

Slow down bodies inside a rectangle without changing the world timestep.

```shell
dotnet add package RecursiveAI.OnePhysics
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OnePhysics.Physics2D;
var world = new PhysicsWorld2D();
world.SetTimeScaleRegions([
    new(new(-5, -5), new(5, 5), 0.5f)
]);
var ball = world.AddCircle(0.2f);
ball.LinearVelocity = new(2, 0);
for (int i = 0; i < 60; i++)
    world.Step(1f / 60);
Console.WriteLine(FormattableString.Invariant(
    $"X: {ball.Position.X:F1} m"));
```

Unzip [the example](https://recursiveai.org/onephysics/cookbook/slow-physics-in-a-region/slow-physics-in-a-region.zip), then `dotnet run`.

After one second of world steps, the ball has traveled one meter. The snippet prints:

```text
X: 1.0 m
```

Without the zone, the ball would have traveled 2.0 m in the same world steps, so the zone halves its distance.

## The full program

Both runs use the same pendulum: a circle held two meters from a fixed pivot by a point joint. The second run adds a half-speed rectangle that covers the swing. Neither run changes the step size or the rate at which the world is stepped.

```csharp
using RecursiveAI.OnePhysics.Physics2D;
using RecursiveAI.OnePhysics;
using System.Globalization;

CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
Console.WriteLine($"No zone:         {MeasurePeriod(1):F2} s");
Console.WriteLine($"Half-speed zone: {MeasurePeriod(0.5f):F2} s");

static double MeasurePeriod(float scale)
{
    var world = new PhysicsWorld2D();
    var anchor = world.AddBox(new(0.2f, 0.2f), new(0, 10), type: BodyType.Static);
    // 2 m arm, released 0.3 radians to the right of vertical.
    var bob = world.AddCircle(0.2f, new(2 * Math.Sin(0.3), 10 - 2 * Math.Cos(0.3)));
    world.AddPoint(anchor, bob, new(0, 10));
    if (scale != 1)
        world.SetTimeScaleRegions([new(new(-10, 0), new(10, 20), scale)]);

    const float dt = 1f / 60;
    var crossings = new List<double>();
    double previousX = bob.Position.X;
    for (int tick = 1; tick <= 3600 && crossings.Count < 4; tick++)
    {
        world.Step(dt);
        double x = bob.Position.X;
        if (previousX < 0 && x >= 0)
            crossings.Add((tick - 1 + (-previousX / (x - previousX))) * dt);
        previousX = x;
    }

    if (crossings.Count != 4)
        throw new InvalidOperationException("Expected four left-to-right crossings.");
    return (crossings[^1] - crossings[0]) / 3;
}
```

`dotnet run` prints:

```text
No zone:         2.86 s
Half-speed zone: 5.72 s
```

The program interpolates between the two samples around each left-to-right crossing of `X = 0`, then averages the time across three full swings. Using crossings in the same direction prevents counting half a swing as a whole one. An out-of-range scale, including `0`, throws `ArgumentOutOfRangeException` when you set the regions.

## Variations

**Slow just the ball.** Remove the `SetTimeScaleRegions` call and add this after setting the ball’s velocity:

```csharp
ball.TimeScale = 0.5f;
```

```text
X: 1.0 m
```

## Related recipes

- [Join two 2D bodies with a joint](https://recursiveai.org/onephysics/cookbook/joints/)
- [Start a 2D physics world](https://recursiveai.org/onephysics/cookbook/2d-physics/)

## The short answer

Set a `TimeScaleRegion2D` with two opposite corners and a factor such as `0.5f`, then keep calling `Step` with your usual fixed timestep. In the example, the pendulum takes 5.72 seconds of world time per swing instead of 2.86 seconds. The zone changes how much time the physics advances, not how often your game calls `Step` or draws the scene.

## How do you make slow-motion physics with a fixed timestep?

Keep the game loop and physics cadence as they are. At 60 updates per second, pass `1f / 60` to `Step` each time, both inside and outside the zone. The [2D API comment](https://github.com/recursive-ai-oss/onephysics-csharp/blob/11dad30ed91fae25354edb55930c67cc0f71fe25/src/OnePhysics/Physics2D/PhysicsWorld2D.WorldScale.cs#L175-L179) says, “An island advances `dt * scale` each step.” For an isolated body at half scale, each world tick advances the body by half a normal tick. You don’t have to wait for every other frame to update its position.

Pick the rectangle in world coordinates. For the pendulum, both corners are far enough from the pivot that the bob doesn’t cross the boundary. That makes the comparison about the factor, not about how much of each swing the bob spent inside the zone. To adapt it to a doorway or other boundary, step a body across the edge and watch its displacement per tick; the [zone check uses the body’s position](https://github.com/recursive-ai-oss/onephysics-csharp/blob/11dad30ed91fae25354edb55930c67cc0f71fe25/src/OnePhysics/Core/WorldCore.Scale.cs#L179-L186), not the shape’s outer edge.

When a moving body is touching or jointed to another dynamic body, they may be in the same *island*, a group of bodies the solver handles together. The [world-scale guide](https://recursiveai.org/onephysics/docs/world-scale/) says, “Time scale applies per island, at the smallest scale of its bodies.” An object outside the rectangle can therefore share the slower rate while it touches a slow object. Don’t use the rectangle as a promise that every body outside its bounds keeps moving at normal speed.

Overlapping rectangles do not stack: the [region lookup](https://github.com/recursive-ai-oss/onephysics-csharp/blob/11dad30ed91fae25354edb55930c67cc0f71fe25/src/OnePhysics/Core/WorldScaleStore.cs#L73-L84) picks the smallest scale among the matching rectangles. A body’s own `TimeScale` multiplies that regional factor. If you want two nested zones, specify each zone’s intended rate rather than expressing the inner one as a fraction of the outer one.
