rigid_body_dominance
Dominance is a non-realistic, but sometimes useful, feature. It can be used to make one rigid-body immune to forces originating from contacts with some other bodies. For example this can be used to model a player represented as a dynamic rigid-body that cannot be "pushed back" by any, or some, other dynamic rigid-bodies part of the environment.
Each rigid-body is part of a dominance group in [-127; 127]
(the default group is 0
). If the colliders from two rigid-bodies
are in contact, the one with the highest dominance will act as if it has an infinite mass, making it immune to the
contact forces the other body would apply on it. If both bodies are part of the same dominance group, then their
contacts will work in the usual way (both are affected by opposite forces with the same magnitude).
For example, if a dynamic body A
is in the dominance group 10
, and a dynamic body B
in the dominance group -20
, then
a contact between a collider attached to A
and a collider attached B
will result in A
remaining immobile and B
being
pushed by A
(independently from their mass).
A non-dynamic rigid-body is always considered as being part of a dominance group greater than any dynamic rigid-body. This means that dynamic/fixed and dynamic/kinematic contacts will continue to work normally, independently from the dominance group they were given by the user.
The dominance group can be set when the rigid-body is created or after its creation:
/* Set the damping coefficients when the rigid-body is created. */
let rigidBodyDesc = RAPIER.RigidBodyDesc.dynamic()
.setDominanceGroup(10);
let rigidBody = world.createRigidBody(rigidBodyDesc);
/* Set the damping coefficients after the rigid-body creation. */
rigidBody.setDominanceGroup(10);