S&box Wiki

Joints

This page is a work-in-progress. More sections and fact-checking are needed.

Overview

A PhysicsJoint constrains the motion of one PhysicsBody relative to another. If a PhysicsBody is dynamic, any joints attached to it may influence its movement.

For example, consider two cubes connected by a SpringJoint. Each cube has a BoxCollider component that defines its shape in the PhysicsWorld, along with a Rigidbody component that provides a dynamic PhysicsBody for the collider to attach to.

sbox-dev_iwL4qnCs3S.png

When the first cube is pulled, the second follows behind due to the spring force.

If a body is static or keyframed, joints will not influence its movement. However, any dynamic body connected to the same joint may still be affected.

Joint Components

In the Scene Editor, PhysicsJoints can be created by adding a Joint Component to a GameObject. Each type of joint provides different movement constraints, which are described below.

A joint component does not need to be on the same GameObject as the Rigidbody. This allows for offsets, such as hinges positioned away from the connected bodies.
sbox-dev_FWWnEuAMNx.png

in C# you can use the Attachment property to control what reference frame the body uses. If you use Joint.AttachmentMode.Auto, the joint will maintain the position and rotation at the time of attachment. Joint.AttachmentMode.LocalFrames will make the joint connect at the center of it's attached rigidbody.

Fixed Joint

A FixedJoint welds two physics objects together, keeping them at a fixed distance while also maintaining their relative rotation.

Frequency and Angular Frequency control the stiffness of the joint.

Spring Joint

A SpringJoint tries to maintain a set distance between two objects.

Frequency controls the stiffness of the spring.

Min Length defines how close the objects can get before being pushed apart.

Max Length defines how far they can separate before being pulled back together.

Slider Joint

A SliderJoint constrains movement to the Z-axis relative to the connected body, similar to a drawer opening and closing.

Min Length and Max Length define the range of movement along the axis.

Hinge Joint

A HingeJoint allows two physics objects to rotate around a single axis, like a door hinge.

Ball Joint

A BallJoint fixes two objects together while allowing rotation in any direction, similar to a shoulder joint. It supports optional twist and angular limits.