---
title: "Make a 2D physics conveyor belt in C#"
url: https://recursiveai.org/onephysics/cookbook/make-a-2d-physics-conveyor-belt/
description: "Make a 2D physics conveyor belt in C#. Set contact surface velocity with OnePhysics and compare the box’s speed with the belt on and off."
version: "1.3.0"
---

# Make a 2D physics conveyor belt 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/make-a-2d-physics-conveyor-belt/make-a-2d-physics-conveyor-belt.zip)

Set the contact’s `TangentSpeed` to give the belt a surface velocity that carries the box while the collider stays put.

```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 System;
using static System.FormattableString;
using RecursiveAI.OnePhysics;
using RecursiveAI.OnePhysics.Physics2D;

var world = new PhysicsWorld2D();
world.AddBox(new(12, 1), new(0, -0.5),
    type: BodyType.Static);
var box = world.AddBox(new(1, 1),
    new(0, 0.5));
world.ContactModifier =
    (ref ContactModification contact) =>
        contact.TangentSpeed = 2f;
for (int i = 0; i < 120; i++)
    world.Step(1f / 60);
Console.WriteLine(Invariant(
    $"Box vx: {box.LinearVelocity.X:F2} m/s"));
```

Unzip [the example](https://recursiveai.org/onephysics/cookbook/make-a-2d-physics-conveyor-belt/make-a-2d-physics-conveyor-belt.zip), then `dotnet run`.

Prints the box’s horizontal velocity after two seconds of simulated time:

```text
Box vx: 2.00 m/s
```

## The full program

Run the same scene twice, with the surface speed set to zero and then to a nonzero speed. The callback checks both body handles so it only changes contacts that involve the belt. All inputs are in the code: a stationary box for the belt and a dynamic box resting on its top face.

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

Run("Belt off", 0f);
Run("Belt on", 2f);

static void Run(string label, float speed)
{
    var world = new PhysicsWorld2D();
    var belt = world.AddBox(new(12, 1), new(0, -0.5),
        type: BodyType.Static);
    var box = world.AddBox(new(1, 1), new(0, 0.5));
    var beltHandle = belt.RawHandle;

    world.ContactModifier = (ref ContactModification contact) =>
    {
        if (contact.BodyA == beltHandle || contact.BodyB == beltHandle)
            contact.TangentSpeed = speed;
    };

    for (int i = 0; i < 120; i++)
        world.Step(1f / 60);
    Console.WriteLine(FormattableString.Invariant(
        $"{label}: box vx = {box.LinearVelocity.X:F2} m/s; belt x = {belt.Position.X:F2} m"));
}
```

```text
Belt off: box vx = 0.00 m/s; belt x = 0.00 m
Belt on: box vx = 2.00 m/s; belt x = 0.00 m
```

If the box stays put, check that it makes a solid contact with the belt and that the contact has nonzero friction.

## Variations

**Reverse the belt.** Replace the two `Run` calls in the full program with this call. With the same flat belt and box, reversing the target reverses the box’s velocity.

```csharp
Run("Reverse", -2f);
```

```text
Reverse: box vx = -2.00 m/s; belt x = 0.00 m
```

**Test a frictionless contact.** Replace the callback in the full program with this one. The speed target is still set, but both runs now print zero horizontal velocity for the box.

```csharp
world.ContactModifier = (ref ContactModification contact) =>
{
    if (contact.BodyA == beltHandle || contact.BodyB == beltHandle)
    {
        contact.TangentSpeed = speed;
        contact.Friction = 0f;
    }
};
```

## Related recipes

- [Move a kinematic 2D platform in C#](https://recursiveai.org/onephysics/cookbook/move-a-kinematic-2d-platform/)
- [Make a one-way platform](https://recursiveai.org/onephysics/cookbook/make-one-way-platform/)

## The short answer

Give the conveyor a static collider and set `ContactModification.TangentSpeed` in the world’s `ContactModifier`. The box should be dynamic so it can respond to friction. The belt collider does not translate or rotate; only its contact with another body acts like a moving surface.

## What is a conveyor belt in 2D physics?

A belt does two jobs: it supports a load and drags that load along its surface. The belt in this scene is a flat box. The contact normal points away from its top face, so the normal response supports the load. The tangent lies along the face, so [the friction calculation](https://github.com/recursive-ai-oss/onephysics-csharp/blob/a5f45b1c8e34091892655a5f5536abb14d32528b/src/OnePhysics/Physics2D/ContactKernel2D.cs#L220-L237) can change the box’s horizontal motion without moving the collider.

Use a conveyor for a fixed track that feeds crates toward a drop-off. Use a kinematic platform when the supporting surface itself should change location, as with a lift. Setting a belt’s surface speed won’t move its edges or close a gap in the level.

## How does surface velocity move a box on a conveyor belt?

[`TangentSpeed`](https://github.com/recursive-ai-oss/onephysics-csharp/blob/a5f45b1c8e34091892655a5f5536abb14d32528b/src/OnePhysics/ContactModification.cs#L97-L101) is a target relative speed along the contact tangent, in meters per second. It isn’t a velocity assignment to the box and it doesn’t add the same amount of speed each step. The solver compares the bodies’ relative speed at the contact with the target and limits its correction by friction. That’s why the frictionless variation leaves the box at rest even though the target is set. Once the box is no longer in contact, that belt can no longer pull it toward the target.

The target is along the contact, not always along world X. The positive value in the snippet carries the box right on a flat top face. On a slope, the tangent follows the contact face; on the underside, it can point the other way. If the sides and underside of your collider should behave like ordinary walls, use the contact normal to identify the belt’s working face before setting the speed. `NormalX` and `NormalY` point from `BodyA` toward `BodyB`, so check which body is the belt before interpreting the sign.

The snippet at the top changes every contact because its world has only one possible pair. In a level, use the body-handle check in the full program so a box landing on ordinary ground doesn’t turn that ground into another conveyor. That check applies to the whole belt body. If several shapes share a body but only one is the belt, check `ShapeA` and `ShapeB` instead.

The [callback runs before the solver](https://github.com/recursive-ai-oss/onephysics-csharp/blob/a5f45b1c8e34091892655a5f5536abb14d32528b/src/OnePhysics/Physics2D/PhysicsWorld2D.Contacts.cs#L21-L25). Change the contact there, not the world or the bodies. The callback itself isn’t serialized, so install it on the restored world if you load the scene from a snapshot.
