Skip to main content

rigid_body_mass_properties

The mass properties of a rigid-body is composed of three parts:

  • The mass which determines the resistance of the rigid-body wrt. linear movements. A high mass implies that larger forces are needed to make the rigid-body translate.
  • The angular inertia determines the resistance of the rigid-body wrt. the angular movements. A high angular inertia implies that larger torques are needed to make the rigid-body rotate.
  • The center-of-mass determines relative to what points torques are applied to the rigid-body.
note

Zero is a special value for masses and angular inertia. A mass equal to zero is interpreted as an infinite mass. An angular inertia equal to zero is interpreted as an infinite angular inertia. Therefore, a rigid-body with a mass equal to zero will not be affected by any force, and a rigid-body with an angular inertia equal to zero will not be affected by any torque.

Computing the mass and angular-inertia can often be difficult because they depend on the geometric shape of the object being simulated. This is why they are automatically computed by Rapier when a collider is attached to the rigid-body: the collider add its own mass and angular-inertia contribution (computed based on the collider's shape and density) to the rigid-body it is attached to:

let rigidBodyDesc = RAPIER.RigidBodyDesc.dynamic();
let rigidBody = world.createRigidBody(rigidBodyDesc);
// The default density is 1.0, we are setting 2.0 for this example.
let colliderDesc = RAPIER.ColliderDesc.ball(1.0).setDensity(2.0);
// When the collider is attached, the rigid-body's mass and angular
// inertia is automatically updated to take the collider into account.
world.createCollider(colliderDesc, rigidBody);

Alternatively, it is possible to set the mass properties of a rigid-body when it is created. Keep in mind that this won't prevent the colliders' contributions to be added to these values. So make sure to set the attached colliders' densities to zero if you want your explicit values to be the final mass-properties values.

/* Set the mass-properties when the rigid-body is created. */
let rigidBodyDesc = RAPIER.RigidBodyDesc.dynamic()
.setAdditionalMass(0.5)
// Sets both the mass and angular inertia at once.
.setAdditionalMassProperties(
0.5, // Mass.
{ x: 0.0, y: 1.0 }, // Center of mass.
0.3 // Principal angular inertia.
);
let rigidBody = world.createRigidBody(rigidBodyDesc);