Guides Physics 2D Joints Use HingeJoint2D

Physics 2D Joints 1 min read Updated Apr 2026

Use HingeJoint2D

`HingeJoint2D` rotates around a pivot.

Use it when an object should swing, turn, or spin around one anchor point.

Good Fits

HingeJoint2D is useful for:

  • doors
  • pendulums
  • swinging traps
  • wheels

Scene Setup

  1. Add Rigidbody2D to the moving body.
  2. Add HingeJoint2D.
  3. Assign Connected Body if needed.
  4. Place the hinge Anchor.
  5. Use angle limits if the body should only rotate through part of an arc.
  6. Use the motor if the body should drive itself continuously.

Use Limits for Controlled Swing

Turn on Use Limits when the hinge should not rotate freely.

Then tune:

  • Lower Angle
  • Upper Angle

That is usually what you want for doors, trap arms, and controlled pendulums.

Use the Motor for Powered Rotation

Turn on Use Motor when the hinge should actively rotate.

Then tune:

  • Motor Speed
  • Max Motor Torque

Use the speed first to get the feel right, then add enough torque to make the movement hold up under the scene's physics.

Practical Example: A Heavy Door

For a simple heavy door:

  1. Add Rigidbody2D to the door.
  2. Add HingeJoint2D.
  3. Set the anchor at the hinge side of the door.
  4. Enable limits.
  5. Start with a modest range like 0 to 110.

This gives you a scene-authored door instead of a rotation script fighting the physics body.

PHP Example

<?php

use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\HingeJoint2D;

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

        $joint->useMotor = true;
        $joint->motorSpeed = 180.0;
        $joint->maxMotorTorque = 1200.0;
    }
}

Related Guides