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
- Add
Rigidbody2Dto the moving body. - Add
SliderJoint2D. - Assign
Connected Bodyif needed. - Set the
Axis. - Enable limits if the body should only travel within a range.
- 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 TranslationUpper 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 SpeedMax Motor Force
Practical Example: Simple Elevator
For a simple moving elevator:
- Add
SliderJoint2D. - Set the axis to vertical.
- Enable limits.
- Give it a lower and upper travel range.
- 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;
}
}