Skip to content

Commit

Permalink
Some more related to colliders
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri authored and sebcrozet committed Sep 30, 2023
1 parent 91dd31e commit bd387e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/geometry/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub enum ComputedColliderShape {
/// - [`CollisionGroups`]
/// - [`SolverGroups`]
/// - [`ActiveCollisionTypes`]
/// - [`ActiveEvents`]
/// - [`ContactForceEventThreshold`]
/// - [`CollidingEntities`]
/// - [`ColliderScale`]
/// - [`ColliderDisabled`]
Expand Down Expand Up @@ -453,16 +455,16 @@ impl From<ActiveHooks> for rapier::pipeline::ActiveHooks {
#[derive(Default, Component, Reflect, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
#[reflect(Component)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
/// Flags affecting the events generated for this collider.
/// Flags affecting the events generated for this [`Collider`].
pub struct ActiveEvents(u32);

bitflags::bitflags! {
impl ActiveEvents: u32 {
/// If set, Rapier will call `EventHandler::handle_collision_event`
/// whenever relevant for this collider.
/// whenever relevant for this [`Collider`].
const COLLISION_EVENTS = 0b0001;
/// If set, Rapier will call `EventHandler::handle_contact_force_event`
/// whenever relevant for this collider.
/// whenever relevant for this [`Collider`].
const CONTACT_FORCE_EVENTS = 0b0010;
}
}
Expand All @@ -474,7 +476,10 @@ impl From<ActiveEvents> for rapier::pipeline::ActiveEvents {
}
}

/// The total force magnitude beyond which a contact force event can be emitted.
/// The total force magnitude beyond which a [`ContactForceEvent`] can be emitted.
///
/// This requires that the [`ActiveEvents::CONTACT_FORCE_EVENTS`] flag is set on the
/// entity.
#[derive(Copy, Clone, PartialEq, Component, Reflect)]
#[reflect(Component)]
pub struct ContactForceEventThreshold(pub f32);
Expand Down
8 changes: 7 additions & 1 deletion src/pipeline/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use std::collections::HashMap;
use std::sync::RwLock;

/// Events occurring when two colliders start or stop colliding
///
/// This will only get triggered if the entity has the
/// [`ActiveEvent::COLLISION_EVENTS`] flag enabled.
#[derive(Event, Copy, Clone, Debug, PartialEq, Eq)]
pub enum CollisionEvent {
/// Event occurring when two colliders start colliding
Expand All @@ -19,7 +22,10 @@ pub enum CollisionEvent {
}

/// Event occurring when the sum of the magnitudes of the contact forces
/// between two colliders exceed a threshold.
/// between two colliders exceed a threshold ([`ContactForceEventThreshold`]).
///
/// This will only get triggered if the entity has the
/// [`ActiveEvent::CONTACT_FORCE_EVENTS`] flag enabled.
#[derive(Event, Copy, Clone, Debug, PartialEq)]
pub struct ContactForceEvent {
/// The first collider involved in the contact.
Expand Down

0 comments on commit bd387e7

Please sign in to comment.