Ammo.js 6 Degrees of Freedom Constraint Parameters

This article explains how to configure a 6 Degrees of Freedom (6DoF) constraint in the ammo.js physics engine. It details the required constructor arguments, transform frames, and limit-setting parameters necessary to precisely control the translational and rotational movement between two rigid bodies.

The 6 Degrees of Freedom constraint in ammo.js is represented by the btGeneric6DofConstraint class. It allows you to restrict or free movement along three translational axes (X, Y, Z) and three rotational axes (pitch, yaw, roll).

Constructor Parameters

To instantiate a 6DoF constraint, you use the Ammo.btGeneric6DofConstraint constructor. The most common constructor signature requires the following parameters:

Setting Linear Limits

Linear limits control translation along the local X, Y, and Z axes. If the lower limit is higher than the upper limit, the axis is completely free. If the lower limit is equal to the upper limit, the axis is locked.

Setting Angular Limits

Angular limits control rotation around the local X, Y, and Z axes. The rotational axes are indexed as 3, 4, and 5 (representing X, Y, and Z rotation respectively).

Advanced Parameters: Springs and Motors

To add bounce, suspension, or powered movement to the constraint, you can configure spring and motor parameters for each axis (indices 0 to 5, where 0-2 are linear and 3-5 are angular):