Guides Physics 2D Joints Use SliderJoint2D

Physics 2D Joints 2 min read Updated Apr 2026

Use SliderJoint2D

`SliderJoint2D` constrains movement to one axis.

Use it when a body should slide, travel, or be driven along a single line instead of moving freely in every direction.

Good Fits

SliderJoint2D is useful for:

  • elevators
  • pistons
  • push/pull rails
  • moving mechanical platforms

Scene Setup

  1. Add Rigidbody2D to the moving body.
  2. Add SliderJoint2D.
  3. Assign Connected Body if needed.
  4. Set the Axis.
  5. Enable limits if the body should only travel within a range.
  6. Enable the motor if the body should actively move itself along that axis.

Scene View Helps Here

SliderJoint2D is easiest to tune visually.

Use the Scene view to:

  • place the anchors
  • drag the axis direction
  • verify the travel lane before pressing play

That is usually faster than trying to guess a good axis from raw numbers alone.

Use Limits for Bounded Travel

Turn on Use Limits when the body should only move inside a travel window.

Then tune:

  • Lower Translation
  • Upper Translation

This is the normal setup for elevators, trap rails, and puzzle sliders.

Use the Motor for Powered Travel

Turn on Use Motor when the joint should actively push along the axis.

Then tune:

  • Motor Speed
  • Max Motor Force

Practical Example: Simple Elevator

For a simple moving elevator:

  1. Add SliderJoint2D.
  2. Set the axis to vertical.
  3. Enable limits.
  4. Give it a lower and upper travel range.
  5. Turn on the motor and tune the speed.

That gives you a scene-authored moving platform without needing to script the whole travel path from scratch.

PHP Example

<?php

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\SliderJoint2D;
use Lenga\Engine\Core\Vector3;

class ElevatorMotor extends Behaviour
{
    public function awake(): void
    {
        $joint = $this->gameObject->getComponent(SliderJoint2D::class);
        if ($joint === null) {
            return;
        }

        $joint->axis = new Vector3(0.0, 1.0, 0.0);
        $joint->useLimits = true;
        $joint->lowerTranslation = 0.0;
        $joint->upperTranslation = 6.0;
        $joint->useMotor = true;
        $joint->motorSpeed = 1.5;
        $joint->maxMotorForce = 2500.0;
    }
}

Related Guides