pub struct Collider {
pub user_data: u128,
/* private fields */
}Expand description
The collision shape attached to a rigid body that defines what it can collide with.
Think of a collider as the “hitbox” or “collision shape” for your physics object. While a
RigidBody handles the physics (mass, velocity, forces),
the collider defines what shape the object has for collision detection.
§Key concepts
- Shape: The geometric form (box, sphere, capsule, mesh, etc.)
- Material: Physical properties like friction (slipperiness) and restitution (bounciness)
- Sensor vs. Solid: Sensors detect overlaps but don’t create physical collisions
- Mass properties: Automatically computed from the shape’s volume and density
§Creating colliders
Always use ColliderBuilder to create colliders:
let collider = ColliderBuilder::cuboid(1.0, 0.5, 1.0) // 2x1x2 box
.friction(0.7)
.restitution(0.3);
colliders.insert_with_parent(collider, body_handle, &mut bodies);§Attaching to bodies
Colliders are usually attached to rigid bodies. One body can have multiple colliders to create compound shapes (like a character with separate colliders for head, torso, limbs).
Fields§
§user_data: u128User-defined data associated to this collider.
Implementations§
Source§impl Collider
impl Collider
Sourcepub fn parent(&self) -> Option<RigidBodyHandle>
pub fn parent(&self) -> Option<RigidBodyHandle>
The rigid body this collider is attached to, if any.
Returns None for standalone colliders (not attached to any body).
Sourcepub fn is_sensor(&self) -> bool
pub fn is_sensor(&self) -> bool
Checks if this collider is a sensor (detects overlaps without physical collision).
Sensors are like “trigger zones” - they detect when other colliders enter/exit them but don’t create physical contact forces. Use for:
- Trigger zones (checkpoint areas, damage regions)
- Proximity detection
- Collectible items
- Area-of-effect detection
Sourcepub fn copy_from(&mut self, other: &Collider)
pub fn copy_from(&mut self, other: &Collider)
Copy all the characteristics from other to self.
If you have a mutable reference to a collider collider: &mut Collider, attempting to
assign it a whole new collider instance, e.g., *collider = ColliderBuilder::ball(0.5).build(),
will crash due to some internal indices being overwritten. Instead, use
collider.copy_from(&ColliderBuilder::ball(0.5).build()).
This method will allow you to set most characteristics of this collider from another collider instance without causing any breakage.
This method cannot be used for reparenting a collider. Therefore, the parent of the
other (if any), as well as its relative position to that parent will not be copied into
self.
The pose of other will only copied into self if self doesn’t have a parent (if it has
a parent, its position is directly controlled by the parent rigid-body).
Sourcepub fn active_hooks(&self) -> ActiveHooks
pub fn active_hooks(&self) -> ActiveHooks
Which physics hooks are enabled for this collider.
Hooks allow custom filtering and modification of collisions. See PhysicsHooks.
Sourcepub fn set_active_hooks(&mut self, active_hooks: ActiveHooks)
pub fn set_active_hooks(&mut self, active_hooks: ActiveHooks)
Enables/disables physics hooks for this collider.
Use to opt colliders into custom collision filtering logic.
Sourcepub fn active_events(&self) -> ActiveEvents
pub fn active_events(&self) -> ActiveEvents
Which events are enabled for this collider.
Controls whether you receive collision/contact force events. See ActiveEvents.
Sourcepub fn set_active_events(&mut self, active_events: ActiveEvents)
pub fn set_active_events(&mut self, active_events: ActiveEvents)
Enables/disables event generation for this collider.
Set to ActiveEvents::COLLISION_EVENTS to receive started/stopped collision notifications.
Set to ActiveEvents::CONTACT_FORCE_EVENTS to receive force threshold events.
Sourcepub fn active_collision_types(&self) -> ActiveCollisionTypes
pub fn active_collision_types(&self) -> ActiveCollisionTypes
The collision types enabled for this collider.
Sourcepub fn set_active_collision_types(
&mut self,
active_collision_types: ActiveCollisionTypes,
)
pub fn set_active_collision_types( &mut self, active_collision_types: ActiveCollisionTypes, )
Sets the collision types enabled for this collider.
Sourcepub fn contact_skin(&self) -> f32
pub fn contact_skin(&self) -> f32
The contact skin of this collider.
See the documentation of ColliderBuilder::contact_skin for details.
Sourcepub fn set_contact_skin(&mut self, skin_thickness: f32)
pub fn set_contact_skin(&mut self, skin_thickness: f32)
Sets the contact skin of this collider.
See the documentation of ColliderBuilder::contact_skin for details.
Sourcepub fn friction(&self) -> f32
pub fn friction(&self) -> f32
The friction coefficient of this collider (how “slippery” it is).
0.0= perfectly slippery (ice)1.0= high friction (rubber on concrete)- Typical values: 0.3-0.8
Sourcepub fn set_friction(&mut self, coefficient: f32)
pub fn set_friction(&mut self, coefficient: f32)
Sets the friction coefficient (slipperiness).
Controls how much this surface resists sliding. Higher values = more grip. Works with other collider’s friction via the combine rule.
Sourcepub fn friction_combine_rule(&self) -> CoefficientCombineRule
pub fn friction_combine_rule(&self) -> CoefficientCombineRule
The combine rule used by this collider to combine its friction coefficient with the friction coefficient of the other collider it is in contact with.
Sourcepub fn set_friction_combine_rule(&mut self, rule: CoefficientCombineRule)
pub fn set_friction_combine_rule(&mut self, rule: CoefficientCombineRule)
Sets the combine rule used by this collider to combine its friction coefficient with the friction coefficient of the other collider it is in contact with.
Sourcepub fn restitution(&self) -> f32
pub fn restitution(&self) -> f32
The restitution coefficient of this collider (how “bouncy” it is).
0.0= no bounce (clay, soft material)1.0= perfect bounce (ideal elastic collision)>1.0= super bouncy (gains energy, unrealistic but fun!)- Typical values: 0.0-0.8
Sourcepub fn set_restitution(&mut self, coefficient: f32)
pub fn set_restitution(&mut self, coefficient: f32)
Sets the restitution coefficient (bounciness).
Controls how much velocity is preserved after impact. Higher values = more bounce. Works with other collider’s restitution via the combine rule.
Sourcepub fn restitution_combine_rule(&self) -> CoefficientCombineRule
pub fn restitution_combine_rule(&self) -> CoefficientCombineRule
The combine rule used by this collider to combine its restitution coefficient with the restitution coefficient of the other collider it is in contact with.
Sourcepub fn set_restitution_combine_rule(&mut self, rule: CoefficientCombineRule)
pub fn set_restitution_combine_rule(&mut self, rule: CoefficientCombineRule)
Sets the combine rule used by this collider to combine its restitution coefficient with the restitution coefficient of the other collider it is in contact with.
Sourcepub fn set_contact_force_event_threshold(&mut self, threshold: f32)
pub fn set_contact_force_event_threshold(&mut self, threshold: f32)
Sets the total force magnitude beyond which a contact force event can be emitted.
Sourcepub fn set_sensor(&mut self, is_sensor: bool)
pub fn set_sensor(&mut self, is_sensor: bool)
Converts this collider to/from a sensor.
Sensors detect overlaps but don’t create physical contact forces.
Use true for trigger zones, false for solid collision shapes.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if this collider is active in the simulation.
Disabled colliders are excluded from collision detection and physics.
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enables or disables this collider.
When disabled, the collider is excluded from all collision detection and physics. Useful for temporarily “turning off” colliders without removing them.
Sourcepub fn set_translation(&mut self, translation: Vector<f32>)
pub fn set_translation(&mut self, translation: Vector<f32>)
Sets the collider’s position (for standalone colliders).
For attached colliders, modify the parent body’s position instead. This directly sets world-space position.
Sourcepub fn set_rotation(&mut self, rotation: Rotation<f32>)
pub fn set_rotation(&mut self, rotation: Rotation<f32>)
Sets the collider’s rotation (for standalone colliders).
For attached colliders, modify the parent body’s rotation instead.
Sourcepub fn set_position(&mut self, position: Isometry<f32>)
pub fn set_position(&mut self, position: Isometry<f32>)
Sets the collider’s full pose (for standalone colliders).
For attached colliders, modify the parent body instead.
Sourcepub fn position(&self) -> &Isometry<f32>
pub fn position(&self) -> &Isometry<f32>
The current world-space position of this collider.
For attached colliders, this is automatically updated when the parent body moves. For standalone colliders, this is the position you set directly.
Sourcepub fn translation(&self) -> &Vector<f32>
pub fn translation(&self) -> &Vector<f32>
The current position vector of this collider (world coordinates).
Sourcepub fn position_wrt_parent(&self) -> Option<&Isometry<f32>>
pub fn position_wrt_parent(&self) -> Option<&Isometry<f32>>
The collider’s position relative to its parent body (local coordinates).
Returns None for standalone colliders. This is the offset from the parent body’s origin.
Sourcepub fn set_translation_wrt_parent(&mut self, translation: Vector<f32>)
pub fn set_translation_wrt_parent(&mut self, translation: Vector<f32>)
Changes this collider’s position offset from its parent body.
Useful for adjusting where a collider sits on a body without moving the whole body. Does nothing if the collider has no parent.
Sourcepub fn set_rotation_wrt_parent(&mut self, rotation: AngVector<f32>)
pub fn set_rotation_wrt_parent(&mut self, rotation: AngVector<f32>)
Changes this collider’s rotation offset from its parent body.
Rotates the collider relative to its parent. Does nothing if no parent.
Sourcepub fn set_position_wrt_parent(&mut self, pos_wrt_parent: Isometry<f32>)
pub fn set_position_wrt_parent(&mut self, pos_wrt_parent: Isometry<f32>)
Changes this collider’s full pose (position + rotation) relative to its parent.
Does nothing if the collider is not attached to a rigid-body.
Sourcepub fn collision_groups(&self) -> InteractionGroups
pub fn collision_groups(&self) -> InteractionGroups
The collision groups controlling what this collider can interact with.
See InteractionGroups for details on collision filtering.
Sourcepub fn set_collision_groups(&mut self, groups: InteractionGroups)
pub fn set_collision_groups(&mut self, groups: InteractionGroups)
Changes which collision groups this collider belongs to and can interact with.
Use to control collision filtering (like changing layers).
Sourcepub fn solver_groups(&self) -> InteractionGroups
pub fn solver_groups(&self) -> InteractionGroups
The solver groups for this collider (advanced collision filtering).
Most users should use collision_groups() instead.
Sourcepub fn set_solver_groups(&mut self, groups: InteractionGroups)
pub fn set_solver_groups(&mut self, groups: InteractionGroups)
Changes the solver groups (advanced contact resolution filtering).
Sourcepub fn material(&self) -> &ColliderMaterial
pub fn material(&self) -> &ColliderMaterial
Returns the material properties (friction and restitution) of this collider.
Sourcepub fn volume(&self) -> f32
pub fn volume(&self) -> f32
Returns the volume (3D) or area (2D) of this collider’s shape.
Used internally for mass calculations when density is set.
Sourcepub fn density(&self) -> f32
pub fn density(&self) -> f32
The density of this collider (mass per unit volume).
Used to automatically compute mass from the collider’s volume. Returns an approximate density if mass was set directly instead.
Sourcepub fn mass(&self) -> f32
pub fn mass(&self) -> f32
The mass contributed by this collider to its parent body.
Either set directly or computed from density × volume.
Sourcepub fn set_density(&mut self, density: f32)
pub fn set_density(&mut self, density: f32)
Sets the uniform density of this collider.
This will override any previous mass-properties set by Self::set_density,
Self::set_mass, Self::set_mass_properties, ColliderBuilder::density,
ColliderBuilder::mass, or ColliderBuilder::mass_properties
for this collider.
The mass and angular inertia of this collider will be computed automatically based on its shape.
Sourcepub fn set_mass(&mut self, mass: f32)
pub fn set_mass(&mut self, mass: f32)
Sets the mass of this collider.
This will override any previous mass-properties set by Self::set_density,
Self::set_mass, Self::set_mass_properties, ColliderBuilder::density,
ColliderBuilder::mass, or ColliderBuilder::mass_properties
for this collider.
The angular inertia of this collider will be computed automatically based on its shape and this mass value.
Sourcepub fn set_mass_properties(&mut self, mass_properties: MassProperties)
pub fn set_mass_properties(&mut self, mass_properties: MassProperties)
Sets the mass properties of this collider.
This will override any previous mass-properties set by Self::set_density,
Self::set_mass, Self::set_mass_properties, ColliderBuilder::density,
ColliderBuilder::mass, or ColliderBuilder::mass_properties
for this collider.
Sourcepub fn shape(&self) -> &dyn Shape
pub fn shape(&self) -> &dyn Shape
The geometric shape of this collider (ball, cuboid, mesh, etc.).
Returns a reference to the underlying shape object for reading properties or performing geometric queries.
Sourcepub fn shape_mut(&mut self) -> &mut dyn Shape
pub fn shape_mut(&mut self) -> &mut dyn Shape
A mutable reference to the geometric shape of this collider.
If that shape is shared by multiple colliders, it will be
cloned first so that self contains a unique copy of that
shape that you can modify.
Sourcepub fn set_shape(&mut self, shape: SharedShape)
pub fn set_shape(&mut self, shape: SharedShape)
Sets the shape of this collider.
Returns the shape as a SharedShape (reference-counted shape).
Use shape() for the trait object, this for the concrete type.
Sourcepub fn compute_aabb(&self) -> Aabb
pub fn compute_aabb(&self) -> Aabb
Computes the axis-aligned bounding box (AABB) of this collider.
The AABB is the smallest box (aligned with world axes) that contains the shape. Doesn’t include contact skin.
Sourcepub fn compute_collision_aabb(&self, prediction: f32) -> Aabb
pub fn compute_collision_aabb(&self, prediction: f32) -> Aabb
Computes the AABB including contact skin and prediction distance.
This is the AABB used for collision detection (slightly larger than the visual shape).
Sourcepub fn compute_swept_aabb(&self, next_position: &Isometry<f32>) -> Aabb
pub fn compute_swept_aabb(&self, next_position: &Isometry<f32>) -> Aabb
Computes the AABB swept from current position to next_position.
Returns a box that contains the shape at both positions plus everything in between. Used for continuous collision detection.
Sourcepub fn compute_broad_phase_aabb(
&self,
params: &IntegrationParameters,
bodies: &RigidBodySet,
) -> Aabb
pub fn compute_broad_phase_aabb( &self, params: &IntegrationParameters, bodies: &RigidBodySet, ) -> Aabb
Computes the collider’s AABB for usage in a broad-phase.
It takes into account soft-ccd, the contact skin, and the contact prediction.
Sourcepub fn mass_properties(&self) -> MassProperties
pub fn mass_properties(&self) -> MassProperties
Computes the full mass properties (mass, center of mass, angular inertia).
Returns properties in the collider’s local coordinate system.
Sourcepub fn contact_force_event_threshold(&self) -> f32
pub fn contact_force_event_threshold(&self) -> f32
Returns the force threshold for contact force events.
When contact forces exceed this value, a ContactForceEvent is generated.
See set_contact_force_event_threshold() for details.
Trait Implementations§
Source§impl From<ColliderBuilder> for Collider
impl From<ColliderBuilder> for Collider
Source§fn from(val: ColliderBuilder) -> Collider
fn from(val: ColliderBuilder) -> Collider
Source§impl HasModifiedFlag for Collider
impl HasModifiedFlag for Collider
Source§fn has_modified_flag(&self) -> bool
fn has_modified_flag(&self) -> bool
Source§fn set_modified_flag(&mut self)
fn set_modified_flag(&mut self)
Auto Trait Implementations§
impl Freeze for Collider
impl !RefUnwindSafe for Collider
impl Send for Collider
impl Sync for Collider
impl Unpin for Collider
impl !UnwindSafe for Collider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.