What Parameters Are Required for a planck.js Prismatic Joint?

Setting up a Prismatic Joint in planck.js requires defining a specific set of parameters and configuration properties to constrain two rigid bodies to move along a single linear axis of translation without rotating relative to each other. This article provides a comprehensive breakdown of the essential initialization parameters—including the body references, local anchor points, and the world axis vector—as well as the optional control parameters like joint limits and motor settings.


Essential Initialization Parameters

A Prismatic Joint constrains two bodies so they can only slide relative to one another along a specified axis. To initialize this joint using planck.PrismaticJoint(def), or via the shortcut world.createJoint(planck.PrismaticJoint(def)), you must populate a joint definition object with several foundational parameters.

1. Body References

Like all joints in planck.js, you must explicitly state which two physics bodies are being linked.

2. Anchor Points

Anchor points define the exact location where the joint is attached on each body.

3. The Axis of Motion

4. Reference Angle


The PrismaticJointDef.initialize Helper

Manually calculating local anchors and axes can be tedious. To simplify setup, planck.js provides a helper function that automatically calculates these local coordinates based on world coordinates:

// Function signature
PrismaticJointDef.initialize(bodyA, bodyB, anchor, axis);

When using this method, the required parameters are:


Optional Control Parameters

Once the fundamental structural parameters are set, you can optionally configure limits and motor properties within the definition object to control the behavior of the joint.

Motion Limits

To prevent the sliding body from traveling infinitely along the axis, you can restrict its range of motion.

Motor Settings

The Prismatic Joint includes a built-in linear motor that can apply force to drive the sliding motion automatically.