Course contentsShow
← Unity Game Development
Lesson 198 of 8283. Physics and InteractionFree lesson

Building Complex Pulley Systems with Configurable Joints

Implement configurable joints to link multiple objects together, enabling the creation of functional pulleys and counterweight mechanisms.

In this lesson, you will learn how to create a functional pulley system by using ConfigurableJoints to chain physics objects together, allowing for realistic counterweight mechanisms.

The Anatomy of a Pulley

While Unity has a HingeJoint, it is often too limited for complex, multi-part machines. A ConfigurableJoint is the "Swiss Army Knife" of physics; it allows us to restrict specific degrees of freedom (DOF) while keeping others loose. To build a pulley, we treat the joint as a constraint that forces two objects—like a load and a counterweight—to follow a specific path relative to one another.

Implementing the Connection

To build a basic pulley, you need three main components: a static anchor (the ceiling), a pulley wheel, and the connected weights.

  1. Setup: Create a Rigidbody for your weight and attach a ConfigurableJoint.
  2. Anchor the Motion: Set the Connected Body to your pulley system’s anchor point.
  3. Lock Degrees of Freedom: Under the joint settings, lock the Angular X, Y, Z Motion to Locked to prevent the weight from spinning wildly. If you want the weight to move strictly up and down, set the Linear X and Linear Z to Locked, leaving only Linear Y as Limited.
  4. Setting Limits: Expand the Linear Limit section and set the Limit value to define how far the weight can travel.

Here is how you might configure a weight script to ensure it remains responsive:

void ConfigurePulleyJoint(ConfigurableJoint joint)
{
    // Lock all axes except vertical (Y)
    joint.xMotion = ConfigurableJointMotion.Locked;
    joint.yMotion = ConfigurableJointMotion.Limited;
    joint.zMotion = ConfigurableJointMotion.Locked;

    // Define the vertical travel range
    SoftJointLimit limit = new SoftJointLimit();
    limit.limit = 5.0f; 
    joint.linearLimit = limit;
}

Why Configurable?

The beauty of the ConfigurableJoint lies in the Drive settings. By modifying the Y Drive, you can apply a "Spring" or "Position" force that pulls the weight back toward a target position, effectively simulating the tension of a rope without needing to write a complex custom physics solver. This allows your counterweights to react dynamically to collisions or external forces.

Key Takeaway: By locking specific linear and angular axes within a ConfigurableJoint, you can restrict physics objects to move along defined paths, creating stable and reactive mechanical systems like pulleys and lifts.