#[repr(C)]pub struct InteractionGroups {
pub memberships: Group,
pub filter: Group,
pub test_mode: InteractionTestMode,
}Expand description
Collision filtering system that controls which colliders can interact with each other.
Think of this as “collision layers” in game engines. Each collider has:
- Memberships: What groups does this collider belong to? (up to 32 groups)
- Filter: What groups can this collider interact with?
An interaction is allowed between two colliders a and b when two conditions
are met simultaneously for InteractionTestMode::And or individually for InteractionTestMode::Or::
- The groups membership of
ahas at least one bit set to1in common with the groups filter ofb. - The groups membership of
bhas at least one bit set to1in common with the groups filter ofa.
In other words, interactions are allowed between two colliders iff. the following condition is met
for InteractionTestMode::And:
(self.memberships.bits() & rhs.filter.bits()) != 0 && (rhs.memberships.bits() & self.filter.bits()) != 0or for InteractionTestMode::Or:
(self.memberships.bits() & rhs.filter.bits()) != 0 || (rhs.memberships.bits() & self.filter.bits()) != 0§Common use cases
- Player vs. Enemy bullets: Players in group 1, enemies in group 2. Player bullets only hit group 2, enemy bullets only hit group 1.
- Trigger zones: Sensors that only detect specific object types.
§Example
// Player collider: in group 1, collides with groups 2 and 3
let player_groups = InteractionGroups::new(
Group::GROUP_1, // I am in group 1
Group::GROUP_2, | Group::GROUP_3, // I collide with groups 2 and 3
InteractionTestMode::And
);
// Enemy collider: in group 2, collides with group 1
let enemy_groups = InteractionGroups::new(
Group::GROUP_2, // I am in group 2
Group::GROUP_1, // I collide with group 1
InteractionTestMode::And
);
// These will collide because:
// - Player's membership (GROUP_1) is in enemy's filter (GROUP_1) ✓
// - Enemy's membership (GROUP_2) is in player's filter (GROUP_2) ✓
assert!(player_groups.test(enemy_groups));Fields§
§memberships: GroupGroups memberships.
filter: GroupGroups filter.
test_mode: InteractionTestModeInteraction test mode
In case of different test modes between two InteractionGroups, InteractionTestMode::And is given priority.
Implementations§
Source§impl InteractionGroups
impl InteractionGroups
Sourcepub const fn new(
memberships: Group,
filter: Group,
test_mode: InteractionTestMode,
) -> Self
pub const fn new( memberships: Group, filter: Group, test_mode: InteractionTestMode, ) -> Self
Initializes with the given interaction groups and interaction mask.
Sourcepub const fn all() -> Self
pub const fn all() -> Self
Creates a filter that allows interactions with everything (default behavior).
The collider is in all groups and collides with all groups.
Sourcepub const fn none() -> Self
pub const fn none() -> Self
Creates a filter that prevents all interactions.
The collider won’t collide with anything. Useful for temporarily disabled colliders.
Sourcepub const fn with_memberships(self, memberships: Group) -> Self
pub const fn with_memberships(self, memberships: Group) -> Self
Sets the group this filter is part of.
Sourcepub const fn with_filter(self, filter: Group) -> Self
pub const fn with_filter(self, filter: Group) -> Self
Sets the interaction mask of this filter.
Sourcepub const fn test_and(self, rhs: Self) -> bool
pub const fn test_and(self, rhs: Self) -> bool
Check if interactions should be allowed based on the interaction memberships and filter.
An interaction is allowed iff. the memberships of self contain at least one bit set to 1 in common
with the filter of rhs, and vice-versa.
Sourcepub const fn test_or(self, rhs: Self) -> bool
pub const fn test_or(self, rhs: Self) -> bool
Check if interactions should be allowed based on the interaction memberships and filter.
An interaction is allowed iff. the groups of self contain at least one bit set to 1 in common
with the mask of rhs, or vice-versa.
Sourcepub const fn test(self, rhs: Self) -> bool
pub const fn test(self, rhs: Self) -> bool
Check if interactions should be allowed based on the interaction memberships and filter.
See InteractionTestMode for more info.
Trait Implementations§
Source§impl Clone for InteractionGroups
impl Clone for InteractionGroups
Source§fn clone(&self) -> InteractionGroups
fn clone(&self) -> InteractionGroups
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InteractionGroups
impl Debug for InteractionGroups
Source§impl Default for InteractionGroups
impl Default for InteractionGroups
Source§impl From<InteractionGroups> for QueryFilter<'_>
impl From<InteractionGroups> for QueryFilter<'_>
Source§fn from(groups: InteractionGroups) -> Self
fn from(groups: InteractionGroups) -> Self
Source§impl Hash for InteractionGroups
impl Hash for InteractionGroups
Source§impl PartialEq for InteractionGroups
impl PartialEq for InteractionGroups
impl Copy for InteractionGroups
impl Eq for InteractionGroups
impl StructuralPartialEq for InteractionGroups
Auto Trait Implementations§
impl Freeze for InteractionGroups
impl RefUnwindSafe for InteractionGroups
impl Send for InteractionGroups
impl Sync for InteractionGroups
impl Unpin for InteractionGroups
impl UnwindSafe for InteractionGroups
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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.