collider_friction
Friction is a force that opposes the relative tangential motion between two rigid-bodies with colliders in contact. This force has a direction orthogonal to the contact normal and opposite to the relative rigid-body motion at the contact point. Following the Coulomb friction model, the maximum magnitude of this force is the magnitude of the force along the contact normal multiplied by a friction coefficient. A friction coefficient of 0 implies no friction at all (completely sliding contact) and a coefficient greater or equal to 1 implies a very strong friction. Values greater than 1 are allowed.
Rapier does not make any distinction between the fixed and dynamic friction coefficients currently.
Each collider has its own friction coefficient. This means that when two colliders are in contact, we need to apply a
rule that combines the friction coefficients of these two colliders into a single coefficient that will be used for
the contact. This rule is described by the CoefficientCombineRule
enum:
CoefficientCombineRule.Average
: the average of the two coefficients is used for the contact.CoefficientCombineRule.Min
: the minimum among the two coefficients is used for the contact.CoefficientCombineRule.Multiply
: the product of the two coefficients is used for the contact.CoefficientCombineRule.Max
: the maximum among the two coefficients is used for the contact.
By default, the Average
rule is used. Each collider can be given its own friction combine rule. When two colliders are in
contact, we need to select one of their combine rule. The following precedence is used: Max > Multiply > Min > Average
.
For example if one collider with the Multiply
friction combine rule is in contact with a collider with the Average
friction
combine rule, then the Multiply
rule will be applied for the friction coefficient of this contact (i.e. the coefficients
of both colliders will be multiplied to obtain the coefficient used by the contact).
The CoefficientCombineRule
system exists to cover a wide variety of use-cases efficiently. If this is not flexible
enough, it is possible to get full control over the selection of friction coefficients for each contact point using
contact modification. For example, contact modification allows the
simulation of colliders with non-uniform friction coefficients.
The friction coefficient and friction combine rule can both be set when the collider is created or after its creation:
/* Set the friction coefficient and friction combine rule
when the collider is created. */
let colliderDesc = RAPIER.ColliderDesc.ball(0.5)
.setFriction(0.7)
.setFrictionCombineRule(RAPIER.CoefficientCombineRule.Min);
let collider = world.createCollider(colliderDesc);
/* Set the friction coefficient and friction combine rule
after the collider creation. */
collider.setFriction(0.7);
collider.setFrictionCombineRule(RAPIER.CoefficientCombineRule.Min);