Skip to main content

rigid_body_damping

Damping lets you slow down a rigid-body automatically. This can be used to achieve a wide variety of effects like fake air friction. Each rigid-body is given a linear damping coefficient (affecting its linear velocity) and an angular damping coefficient (affecting its angular velocity). Larger values of the damping coefficients lead to a stronger slow-downs. Their default values are 0.0 (no damping at all).

This damping coefficients can be set when the rigid-body is created or after its creation:

/* Set the damping coefficients when the rigid-body is created. */
let rigid_body = RigidBodyBuilder::dynamic()
.linear_damping(0.5)
.angular_damping(1.0)
.build();
/* Set the damping coefficients after the rigid-body creation. */
let rigid_body = rigid_body_set.get_mut(rigid_body_handle).unwrap();
rigid_body.set_linear_damping(0.5);
rigid_body.set_angular_damping(1.0);
assert_eq!(rigid_body.linear_damping(), 0.5);
assert_eq!(rigid_body.angular_damping(), 1.0);
/* Set damping when the rigid-body bundle is created. */
commands.spawn(RigidBody::Dynamic).insert(Damping {
linear_damping: 0.5,
angular_damping: 1.0,
});
/* Set damping inside of a system. */
fn modify_body_damping(mut dampings: Query<&mut Damping>) {
for mut rb_damping in dampings.iter_mut() {
rb_damping.linear_damping = 0.5;
rb_damping.angular_damping = 1.0;
}
}
/* Set the damping coefficients when the rigid-body is created. */
let rigidBodyDesc = RAPIER.RigidBodyDesc.dynamic()
.setLinearDamping(0.5)
.setAngularDamping(1.0);
let rigidBody = world.createRigidBody(rigidBodyDesc);
/* Set the damping coefficients after the rigid-body creation. */
rigidBody.setLinearDamping(0.5);
rigidBody.setAngularDamping(1.0);