Skip to main content

collider_contact_skin

The contact skin of a collider acts as if the collider was enlarged by a skin of the given thickness: the objects touching it are kept that much further apart. The default is zero, i.e., no skin at all.

A non-zero contact skin can improve the performances and, in some cases, the stability of the simulation, because the contacts will have more room to prevent penetrations. However, as a result it leaves a small gap between the colliding objects, equal to the sum of their skins. Therefore the skin should be small enough for that gap to remain invisible, or to be hidden by the rendering assets. The contact skin is especially relevant when using non-convex shapes made of thin features like triangle meshes and polylines.

/* Set the contact skin when the collider is created. */
let collider = ColliderBuilder::ball(0.5).contact_skin(0.01).build();
/* Set the contact skin after the collider creation. */
let collider = &mut world.colliders[collider_handle];
collider.set_contact_skin(0.01);
assert_eq!(collider.contact_skin(), 0.01);
/* Set the contact skin when the collider is created. */
commands.spawn((Collider::ball(0.5), ContactSkin(0.01)));
/* Set the contact skin inside of a system. */
fn modify_collider_contact_skin(mut contact_skins: Query<&mut ContactSkin>) {
for mut contact_skin in contact_skins.iter_mut() {
contact_skin.0 = 0.01;
}
}
/* Set the contact skin when the collider is created. */
let skinColliderDesc = RAPIER.ColliderDesc.ball(0.5).setContactSkin(0.01);
let skinCollider = world.createCollider(skinColliderDesc);
/* Set the contact skin after the collider creation. */
skinCollider.setContactSkin(0.01);
/* Set the contact skin when the collider is created. */
R2ColliderDesc collider = r2BallColliderDesc(0.5);
collider.contactSkin = 0.01;
/* Set the contact skin after the collider creation. */
r2Collider_SetContactSkin(collider_handle, 0.01);
assert(r2Collider_ContactSkin(collider_handle) == (R2Real)0.01);
# Set the contact skin when the collider is created.
collider = rp.Collider.ball(0.5).contact_skin(0.01).build()
# Set the contact skin after the collider creation.
collider = world.colliders[collider_handle]
collider.contact_skin = 0.01
assert math.isclose(collider.contact_skin, 0.01, rel_tol=1.0e-6)