Skip to content

Joints

Updated

A joint links rigid bodies so they move together under rules: welded into one piece, turning on a hinge, sliding on a rail, swinging on a ball and socket, tied by a rope or pulled by a spring. Joints are how you build doors, wheels, pendulums, chains, drawers, wobbly bridges and chandeliers that fall when their rope is cut. This page explains how a joint chooses the bodies it links, the six joint components and their props, and how a script changes or breaks them.

  • Every body a joint links needs a Rigid Body and a collider.
  • You know the difference between dynamic, kinematic and fixed bodies. A joint usually hangs dynamic bodies from a fixed one.
  • Joints are built with the physics world, in play only.

A joint is a component on a group entity. It links the rigid bodies inside that group:

  • Members. Every entity in the group’s subtree that has a live rigid body is a member, in child order. The group itself is the first member when it has a body. Entities without a Rigid Body are skipped.
  • Anchor. The first member is the anchor.
  • Star. Most joints link every other member back to the anchor.
  • Chain. Rope and Spring joints link each member to the previous one by default, making a chain.
  • Not enough members. A joint with fewer than two members links nothing.
  • Frames. A joint measures where its bodies are the first time it binds, and keeps those measurements when it is rebuilt, so a slack rope stays slack.
  • Self-collision. Linked bodies do not collide with each other unless selfCollide is on.

Pivots, anchors and axes are given in the group’s local space.

  1. Add a Group named Pendulum where the pivot should be. Give it a Rigid Body with type fixed: it is the anchor.
  2. Under it, add a Primitive Mesh sphere two metres below. Give it a Rigid Body (type dynamic) and a Sphere Collider.
  3. On the Pendulum group, add a Spherical Joint and leave its pivot at 0, 0, 0, the group’s origin.
  4. Enter play and give the sphere a push, for example with the script in Push the pendulum. It swings about the pivot.
Component Type What it does
Fixed Joint comp-physics-fixed-joint Welds the bodies together, keeping their poses relative to the anchor: a compound assembly that can still break apart when you disable it.
Revolute Joint comp-physics-revolute-joint A hinge: bodies turn about one shared axis through a pivot. Wheels, fans, doors.
Prismatic Joint comp-physics-prismatic-joint A slider: bodies move along one axis, with every rotation locked. Pistons, drawers, elevators.
Spherical Joint comp-physics-spherical-joint A ball and socket: bodies are pinned at a pivot and turn freely about it. Pendulums, ragdoll shoulders.
Rope Joint comp-physics-rope-joint A maximum distance between bodies, with no force while slack. Ropes, chains, leashes.
Spring Joint comp-physics-spring-joint A soft link that pulls the bodies toward a rest length, damped to settle. Suspensions, bouncy bridges.
Prop Type Default Description
selfCollide boolean false Let the welded bodies still collide with each other.
Prop Type Default Description
pivot { x, y, z } 0, 0, 0 The hinge pivot, in the group’s local space.
axis { x, y, z } 0, 1, 0 The hinge axis, a non-zero direction in the group’s local space.
selfCollide boolean false Let the linked bodies collide with each other.

The axis is expressed in the anchor’s frame. Give the linked bodies the anchor’s orientation when they bind, as you usually would for hinges.

Prop Type Default Description
anchor { x, y, z } 0, 0, 0 The slider anchor, in the group’s local space. The bodies stay aligned through it.
axis { x, y, z } 0, 1, 0 The slide axis, a non-zero direction in the group’s local space.
selfCollide boolean false Let the linked bodies collide with each other.

As with the Revolute Joint, give the linked bodies the anchor’s orientation when they bind.

Prop Type Default Description
pivot { x, y, z } 0, 0, 0 The ball-and-socket pivot, in the group’s local space.
selfCollide boolean false Let the linked bodies collide with each other.

Rope and Spring are link joints. They connect bodies centre to centre and share a topology prop:

Prop Type Default Description
topology 'chain' | 'star' 'chain' chain links each body to the next in child order: anchor, link, link, weight. star links every body back to the anchor, tethering a cluster to one point.
selfCollide boolean false Let the linked bodies collide with each other.

The Rope Joint adds:

Prop Type Default Description
length number spacing at first bind The maximum distance between linked bodies, centre to centre. Left out, it is their distance when the joint first links them: they swing freely but never pull further apart than they started.

The Spring Joint adds:

Prop Type Default Description
restLength number spacing at first bind The separation the spring pulls toward, centre to centre. Left out, it is their distance when the joint first links them.
stiffness number 100 Restoring force per metre of stretch or compression. Higher is stiffer.
damping number 10 Force opposing the rate of length change, which bleeds off oscillation. Higher settles faster.

The default spring constants suit bodies of about one kilogram.

A joint is data. A script changes it like any component:

Action Call Effect
Change a joint joint.setProps({ … }) The joints are rebuilt with the new props.
Break a joint joint.setEnabled(false) The bodies are unlinked and move freely.
Restore it joint.setEnabled(true) The bodies are linked again.
Add a joint group.addComponent(new PhysicsSphericalJointComponent({ … })) Links the group’s bodies from where they are now.

Joints send no events. To know when a linked body is hit, listen to the member bodies’ collision events.

A chandelier hangs from the ceiling on a Rope Joint. When a cut signal arrives, it falls.

CutRope.jx
#pragma lifecycle(startup)
function startup() {
const rope = findEntity('Chandelier').getComponent(PhysicsRopeJointComponent);
on('cut', () => {
rope.setEnabled(false);
log('The rope snaps');
});
}
  • getComponent(PhysicsRopeJointComponent) finds the joint on the group.
  • setEnabled(false) unlinks the bodies. The anchor is fixed, so it stays; the chandelier, dynamic, falls with gravity.
  • Any script or interaction can emit cut, for example a button or a sensor the player walks through.

The pendulum from Build a pendulum gets a sideways kick each time the player presses P.

PushPendulum.jx
#pragma lifecycle(startup, update)
let bob;
function startup() {
bob = findEntity('Bob').getComponent(PhysicsRigidBodyComponent);
}
function update() {
if (Input.keyboard.isKeyReleased(Key.P)) {
bob.applyImpulse({ x: 2, y: 0, z: 0 });
}
}
  • The joint keeps the bob at the same distance from the pivot, so a sideways impulse turns into a swing.
  • Gravity brings it back, and the swing continues until the body’s damping, if any, slows it.
  • You push the member body, not the joint. Joints have no forces of their own.

A rope bridge is a chain of planks on a Spring Joint. Pulling a lever makes it rigid enough to cross.

BridgeLever.jx
#pragma lifecycle(startup)
const WOBBLY = { stiffness: 100, damping: 10 };
const SOLID = { stiffness: 5000, damping: 400 };
let spring;
let solid = false;
function startup() {
spring = findEntity('Bridge').getComponent(PhysicsSpringJointComponent);
on('lever/pulled', () => {
solid = !solid;
spring.setProps(solid ? SOLID : WOBBLY);
log(solid ? 'The bridge holds firm' : 'The bridge sways');
});
}
  • With topology: 'chain', each plank is linked to the one before it, from the anchor out.
  • setProps changes stiffness and damping; the joints are rebuilt with them and keep their first-measured rest length, so the bridge does not jump.
  • High stiffness pulls planks back hard; high damping stops them bouncing.

A door hangs on a Revolute Joint. Each gust turns it with a torque impulse: a shut door blows open, an open one slams shut against its stop.

WindDoor.jx
#pragma lifecycle(startup)
const OPEN_PUSH = 1.35;
const SLAM_PUSH = 6;
function startup() {
const panel = findEntity('Door Panel');
const door = panel.getComponent(PhysicsRigidBodyComponent);
on('weather/gust', (event) => {
if (event.eventType !== EventType.UIButton.Press) return;
// The hinge angle in degrees: 0 when shut, negative when open.
const angle = (2 * Math.atan2(panel.quaternion.y, panel.quaternion.w) * 180) / Math.PI;
const shut = angle > -20;
door.wakeUp();
door.applyTorqueImpulse({ x: 0, y: shut ? -OPEN_PUSH : SLAM_PUSH, z: 0 });
log(shut ? 'The gust blows the door open' : 'The gust slams the door shut');
});
}
  • The Revolute Joint lets the panel turn only about the vertical hinge axis.
  • applyTorqueImpulse about Y turns it around that hinge. A torque about another axis would be resisted by the joint.
  • The panel’s angular damping slows each swing to a stop. Without it, one push would keep the door spinning forever.
  • The Door Stop’s collider is what the door slams against. The Revolute Joint itself has no limits, so the stop sets where the door closes. Continuous collision on the panel keeps a hard slam from passing through the thin stop.
  • The hinge angle, read from the panel’s rotation about Y, decides which way the gust blows, so pressing twice quickly never slams a door that is barely open.
  • wakeUp makes sure a door that has come to rest reacts at once.
  • The button’s Signal Emitter sends its press on weather/gust; the script checks EventType.UIButton.Press.

A statue is built from parts welded with a Fixed Joint. A hard hit breaks it apart.

BreakableStatue.jx
#pragma lifecycle(startup, update)
const BREAK_SPEED = 6;
let weld;
let ball;
let ballSpeed = 0; // last frame's speed, before a hit slows it
let broken = false;
function startup() {
weld = findEntity('Statue').getComponent(PhysicsFixedJointComponent);
ball = findEntity('Wrecking Ball');
on('statue', (event) => {
if (broken || event.eventType !== EventType.PhysicsCollider.CollisionEnter) return;
if (event.data.otherEntityId !== ball.entityId || ballSpeed < BREAK_SPEED) return;
broken = true;
weld.setEnabled(false);
log(`Hit at ${ballSpeed.toFixed(1)} m/s: the weld breaks`);
emit('statue/broken');
});
}
function update() {
const v = ball.getComponent(PhysicsRigidBodyComponent).linearVelocity();
ballSpeed = Math.hypot(v.x, v.y, v.z);
}
  • While the Fixed Joint is on, the parts move as one welded object.
  • Every part reports its contacts on the same signal, so a hit anywhere on the statue counts.
  • A contact event arrives after the physics step has already handled the hit, when the ball has slowed down. update keeps the ball’s speed from the frame before, which is the speed it struck at.
  • Above BREAK_SPEED, setEnabled(false) removes the weld: each part becomes a separate falling body.
  • broken makes sure it breaks once.
  • Putting the joint on a mesh. Joint components are offered on groups only, and link the bodies inside the group.
  • Members without a Rigid Body. Entities without one are skipped. Every linked part needs its own body.
  • A dynamic anchor when you wanted a fixed point. The first member is the anchor. If it is dynamic, the whole assembly falls together. Make it fixed to hang things from it.
  • Pivots in world coordinates. Pivots, anchors and axes are in the group’s local space.
  • Misaligned hinge bodies. For Revolute and Prismatic joints, give the linked bodies the anchor’s orientation before play starts.
  • Waiting for joint events. Joints send none; listen to the member bodies.
  • Toggling bodies every frame. Each body change rebuilds every joint in the scene.