Collider

Struct Collider 

Source
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: u128

User-defined data associated to this collider.

Implementations§

Source§

impl Collider

Source

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).

Source

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
Source

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).

Source

pub fn active_hooks(&self) -> ActiveHooks

Which physics hooks are enabled for this collider.

Hooks allow custom filtering and modification of collisions. See PhysicsHooks.

Source

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.

Source

pub fn active_events(&self) -> ActiveEvents

Which events are enabled for this collider.

Controls whether you receive collision/contact force events. See ActiveEvents.

Source

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.

Source

pub fn active_collision_types(&self) -> ActiveCollisionTypes

The collision types enabled for this collider.

Source

pub fn set_active_collision_types( &mut self, active_collision_types: ActiveCollisionTypes, )

Sets the collision types enabled for this collider.

Source

pub fn contact_skin(&self) -> f32

The contact skin of this collider.

See the documentation of ColliderBuilder::contact_skin for details.

Source

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.

Source

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
Source

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.

Source

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.

Source

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.

Source

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
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn translation(&self) -> &Vector<f32>

The current position vector of this collider (world coordinates).

Source

pub fn rotation(&self) -> &Rotation<f32>

The current rotation/orientation of this collider.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn collision_groups(&self) -> InteractionGroups

The collision groups controlling what this collider can interact with.

See InteractionGroups for details on collision filtering.

Source

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).

Source

pub fn solver_groups(&self) -> InteractionGroups

The solver groups for this collider (advanced collision filtering).

Most users should use collision_groups() instead.

Source

pub fn set_solver_groups(&mut self, groups: InteractionGroups)

Changes the solver groups (advanced contact resolution filtering).

Source

pub fn material(&self) -> &ColliderMaterial

Returns the material properties (friction and restitution) of this collider.

Source

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.

Source

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.

Source

pub fn mass(&self) -> f32

The mass contributed by this collider to its parent body.

Either set directly or computed from density × volume.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_shape(&mut self, shape: SharedShape)

Sets the shape of this collider.

Source

pub fn shared_shape(&self) -> &SharedShape

Returns the shape as a SharedShape (reference-counted shape).

Use shape() for the trait object, this for the concrete type.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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 Clone for Collider

Source§

fn clone(&self) -> Collider

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Collider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ColliderBuilder> for Collider

Source§

fn from(val: ColliderBuilder) -> Collider

Converts to this type from the input type.
Source§

impl HasModifiedFlag for Collider

Source§

fn has_modified_flag(&self) -> bool

Whether the object has been modified
Source§

fn set_modified_flag(&mut self)

Mark object as modified

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.