---
title: "Move a kinematic 2D platform in C#"
url: https://recursiveai.org/onephysics/cookbook/move-a-kinematic-2d-platform/
description: "Move a kinematic 2D platform in C# with OnePhysics. Queue each position before a fixed physics step and see how a dynamic box rides the platform."
version: "1.3.0"
---

# Move a kinematic 2D platform 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/move-a-kinematic-2d-platform/move-a-kinematic-2d-platform.zip)

A kinematic platform follows a path you set. Call `MoveKinematic` before each physics step to move its collider and carry the box.

```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();
var platform = world.AddBox(new(4, 0.5f),
    type: BodyType.Kinematic);
var rider = world.AddBox(new(1, 1),
    new(0, 0.75));
for (int step = 1; step <= 120; step++)
{
    double x = (step <= 60 ? step : 120 - step)
        / 30.0;
    platform.MoveKinematic(new(x, 0), 0f);
    world.Step(1f / 60);
    if (step % 60 != 0) continue;
    double deckX = platform.Position.X;
    double riderX = rider.Position.X;
    Console.WriteLine(Invariant(
        $"{deckX:F2} m, {riderX:F2} m"));
}
```

Unzip [the example](https://recursiveai.org/onephysics/cookbook/move-a-kinematic-2d-platform/move-a-kinematic-2d-platform.zip), then `dotnet run`.

Prints the platform’s and rider’s X positions, in that order, at the turnaround and on return:

```text
2.00 m, 1.66 m
0.00 m, 1.01 m
```

## The full program

The platform starts centered at `(0, 0)` and the box starts centered at `(0, 0.75)`, with its bottom face touching the platform. The platform moves two meters to the right over 60 steps, then returns over 60 more. The program logs both positions every 30 steps so you can see the box slip at the turnaround.

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

const int legSteps = 60;
const double endX = 2.0;
const float dt = 1f / 60;
var world = new PhysicsWorld2D();
var platform = world.AddBox(new(4, 0.5f),
    type: BodyType.Kinematic);
var rider = world.AddBox(new(1, 1), new(0, 0.75));

Log(0);
for (int step = 1; step <= 2 * legSteps; step++)
{
    // 0 m -> 2 m -> 0 m. Queue the next position before stepping.
    double progress = 1.0 - Math.Abs(legSteps - step) / (double)legSteps;
    platform.MoveKinematic(new(endX * progress, 0), angleRadians: 0f);
    world.Step(dt);

    if (step % 30 == 0)
        Log(step);
}

void Log(int step)
{
    Console.WriteLine(FormattableString.Invariant(
        $"Step {step,3}: platform x = {platform.Position.X:F2} m; rider x = {rider.Position.X:F2} m"));
}
```

```text
Step   0: platform x = 0.00 m; rider x = 0.00 m
Step  30: platform x = 1.00 m; rider x = 0.66 m
Step  60: platform x = 2.00 m; rider x = 1.66 m
Step  90: platform x = 1.00 m; rider x = 1.92 m
Step 120: platform x = 0.00 m; rider x = 1.01 m
```

If `MoveKinematic` throws `ArgumentException` when you call it on a platform, check the body type: `AddBox` makes a dynamic body unless you pass `BodyType.Kinematic`.

## Variations

**Move without changing the angle.** Replace the `MoveKinematic` call in the full program with `MovePosition`. It preserves the orientation, so the output is the same in this scene.

```csharp
platform.MovePosition(new(endX * progress, 0));
```

**Make a lift.** Put the target offset on Y instead of X. To print the lift’s motion, log `Position.Y` for both bodies instead of `Position.X`.

```csharp
platform.MoveKinematic(new(0, endX * progress), 0f);
```

At step 60, the platform’s Y is `2.00 m` and the rider’s Y is `2.75 m`. At step 90, the platform is already descending and the rider is above it at `2.51 m`.

## Related recipes

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

## The short answer

Create the platform with `BodyType.Kinematic` and call `MoveKinematic(nextPosition, angleRadians)` before each `Step`. Give it a position for the next step, not the endpoint of the whole trip. The collider itself moves, and the solver sees its motion when the platform touches a dynamic body.

## How do you move a kinematic platform to a point in 2D physics?

Pick a start, an end and a number of fixed steps for each leg. On every step, interpolate between the endpoints, queue the next position, then advance the world. The full program runs that sequence out and back while keeping the angle at zero radians. Key the path to the physics step, so rendering more often doesn’t queue more motion.

[`MoveKinematic`](https://github.com/recursive-ai-oss/onephysics-csharp/blob/a5f45b1c8e34091892655a5f5536abb14d32528b/src/OnePhysics/Physics2D/Body.Controls.cs#L43-L48) queues a target for the **next** step; if you queue several targets before stepping, the last one wins. Calling it once with the far endpoint doesn’t schedule a gradual trip. OnePhysics [derives the velocity from the distance to the target and the step duration](https://github.com/recursive-ai-oss/onephysics-csharp/blob/a5f45b1c8e34091892655a5f5536abb14d32528b/src/OnePhysics/Physics2D/Engine2D.BodyControls.cs#L63-L83). A large jump can exceed the speed limit and make the step throw. Supply smaller increments to spread the trip over more steps.

## How do you keep a rider on a moving 2D platform?

For a dynamic box, start with a solid collider on the platform and let contact and friction do the carrying. Don’t parent the simulated box to the platform or add the deck’s displacement to the box by hand: the solver is already moving the box in response to that contact. A character whose movement is set by game code is a different case; this example only shows a rider whose motion comes from the physics solver.

A rider doesn’t lock to the platform. Compare the X positions at steps 60 and 90: the platform has started to come back, but the box has continued to drift right. It takes time for friction to reverse the box’s motion. If you need the rider to stay near the same spot, try a path that slows before reversing, and log the rider’s position relative to the deck to check whether it still slips.

A lift moves the contact along its normal instead of sliding along the tangent. The deck can push a box up but doesn’t attach the box to itself, so a rapid reversal can leave the box in the air while the deck descends. A one-way platform is a separate choice about which contacts to allow. This recipe moves a solid collider and doesn’t filter contacts from below.
