Skip to main content

collider_type

There are two types of colliders:

  • ColliderType::Solid: solid collidersA solid colliderA solid colliderA solid colliderA solid collider represents a geometric shape that can have contact points with other colliders to generate contact forces to prevent objects from penetrating-each-others.
  • ColliderType::Sensor: sensor collidersSensor collidersSensor collidersSensor collidersSensor colliders on the other end don't generate contacts: they only generate intersection events when one sensor collider and another collider start/stop touching. Sensor colliders are generally used to detect when something enters an area. Note that, for symmetry with non-sensor colliders, sensors do contribute to the mass of a rigid-body they are attached to.

By default a collider is a solid collider. This can be changed to a sensor when constructing the collider, or after its construction:

/* Set the collider type when the collider is created. */
let collider = ColliderBuilder::ball(0.5).sensor(true).build();
/* Set the collider type after the collider creation. */
let collider = &mut world.colliders[collider_handle];
collider.set_sensor(true);
assert!(collider.is_sensor());
/* Set the collider sensor when the collider is created. */
commands.spawn(Collider::ball(0.5)).insert(Sensor);
/* Change the collider sensor status inside of a system. */
fn modify_collider_type(mut commands: Commands, sensors: Query<Entity, With<Sensor>>) {
for entity in sensors.iter() {
commands.entity(entity).remove::<Sensor>();
}
}
/* Set the collider type when the collider is created. */
let colliderDesc = RAPIER.ColliderDesc.ball(0.5)
.setSensor(true);
let collider = world.createCollider(colliderDesc);
/* Set the collider type after the collider creation. */
collider.setSensor(true);
/* Set the collider type when the collider is created. */
R2ColliderDesc collider = r2BallColliderDesc(0.5);
collider.isSensor = 1;
/* Set the collider type after the collider creation. */
r2Collider_SetSensor(collider_handle, 1);
assert(r2Collider_IsSensor(collider_handle));

The sensor status is set with the ColliderBuilder.sensor method, or with the is_sensor property of the collider:

# Set the collider type when the collider is created.
collider = rp.Collider.ball(0.5).sensor(True).build()
# Set the collider type after the collider creation.
collider = world.colliders[collider_handle]
collider.is_sensor = True
assert collider.is_sensor