Struct avian3d::collision::Collisions
source · pub struct Collisions(/* private fields */);
Expand description
A resource that stores all collision pairs.
Each colliding entity pair is associated with Contacts
that can be accessed and modified
using the various associated methods.
§Usage
Collisions
can be accessed at almost anytime, but for modifying and filtering collisions,
it is recommended to use the PostProcessCollisions
schedule. See its documentation
for more information.
§Querying collisions
The following methods can be used for querying existing collisions:
The collisions can be accessed at any time, but modifications to contacts should be performed
in the PostProcessCollisions
schedule. Otherwise, the physics solver will use the old contact data.
§Filtering and removing collisions
The following methods can be used for filtering or removing existing collisions:
Collision filtering and removal should be done in the PostProcessCollisions
schedule.
Otherwise, the physics solver will use the old contact data.
§Adding new collisions
The following methods can be used for adding new collisions:
The most convenient place for adding new collisions is in the PostProcessCollisions
schedule.
Otherwise, the physics solver might not have access to them in time.
§Implementation details
Internally, the collisions are stored in an IndexMap
that contains collisions from both the current frame
and the previous frame, which is used for things like collision events.
However, the public methods only use the current frame’s collisions. To access the internal data structure,
you can use get_internal
or get_internal_mut
.
Implementations§
source§impl Collisions
impl Collisions
sourcepub fn get_internal(
&self
) -> &IndexMap<(Entity, Entity), Contacts, FxBuildHasher>
pub fn get_internal( &self ) -> &IndexMap<(Entity, Entity), Contacts, FxBuildHasher>
Returns a reference to the internal IndexMap
.
sourcepub fn get_internal_mut(
&mut self
) -> &mut IndexMap<(Entity, Entity), Contacts, FxBuildHasher>
pub fn get_internal_mut( &mut self ) -> &mut IndexMap<(Entity, Entity), Contacts, FxBuildHasher>
Returns a mutable reference to the internal IndexMap
.
sourcepub fn get(&self, entity1: Entity, entity2: Entity) -> Option<&Contacts>
pub fn get(&self, entity1: Entity, entity2: Entity) -> Option<&Contacts>
Returns a reference to the contacts stored for the given entity pair if they are colliding,
else returns None
.
The order of the entities does not matter.
sourcepub fn get_mut(
&mut self,
entity1: Entity,
entity2: Entity
) -> Option<&mut Contacts>
pub fn get_mut( &mut self, entity1: Entity, entity2: Entity ) -> Option<&mut Contacts>
Returns a mutable reference to the contacts stored for the given entity pair if they are colliding,
else returns None
.
The order of the entities does not matter.
sourcepub fn contains(&self, entity1: Entity, entity2: Entity) -> bool
pub fn contains(&self, entity1: Entity, entity2: Entity) -> bool
Returns true
if the given entities have been in contact during this frame.
The order of the entities does not matter.
sourcepub fn iter(&self) -> impl Iterator<Item = &Contacts>
pub fn iter(&self) -> impl Iterator<Item = &Contacts>
Returns an iterator over the current collisions that have happened during the current physics frame.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Contacts>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Contacts>
Returns a mutable iterator over the collisions that have happened during the current physics frame.
sourcepub fn collisions_with_entity(
&self,
entity: Entity
) -> impl Iterator<Item = &Contacts>
pub fn collisions_with_entity( &self, entity: Entity ) -> impl Iterator<Item = &Contacts>
Returns an iterator over all collisions with a given entity.
sourcepub fn collisions_with_entity_mut(
&mut self,
entity: Entity
) -> impl Iterator<Item = &mut Contacts>
pub fn collisions_with_entity_mut( &mut self, entity: Entity ) -> impl Iterator<Item = &mut Contacts>
Returns an iterator over all collisions with a given entity.
sourcepub fn insert_collision_pair(&mut self, contacts: Contacts) -> Option<Contacts>
pub fn insert_collision_pair(&mut self, contacts: Contacts) -> Option<Contacts>
Inserts contact data for a collision between two entities.
If a collision entry with the same entities already exists, it will be overwritten,
and the old value will be returned. Otherwise, None
is returned.
Note: Manually inserting collisions can be error prone and should generally be avoided.
If you simply want to modify existing collisions, consider using methods like get_mut
or iter_mut
.
sourcepub fn extend<I: IntoIterator<Item = Contacts>>(&mut self, collisions: I)
pub fn extend<I: IntoIterator<Item = Contacts>>(&mut self, collisions: I)
Extends Collisions
with all collision pairs in the given iterable.
This is mostly equivalent to calling insert_collision_pair
for each of the collision pairs.
sourcepub fn retain<F>(&mut self, keep: F)
pub fn retain<F>(&mut self, keep: F)
Retains only the collisions for which the specified predicate returns true
.
Collisions for which the predicate returns false
are removed.
sourcepub fn remove_collision_pair(
&mut self,
entity1: Entity,
entity2: Entity
) -> Option<Contacts>
pub fn remove_collision_pair( &mut self, entity1: Entity, entity2: Entity ) -> Option<Contacts>
Removes a collision between two entites and returns its value.
The order of the entities does not matter.
sourcepub fn remove_collisions_with_entity(&mut self, entity: Entity)
pub fn remove_collisions_with_entity(&mut self, entity: Entity)
Removes all collisions that involve the given entity.
Trait Implementations§
source§impl Clone for Collisions
impl Clone for Collisions
source§fn clone(&self) -> Collisions
fn clone(&self) -> Collisions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Collisions
impl Debug for Collisions
source§impl Default for Collisions
impl Default for Collisions
source§fn default() -> Collisions
fn default() -> Collisions
source§impl PartialEq for Collisions
impl PartialEq for Collisions
source§fn eq(&self, other: &Collisions) -> bool
fn eq(&self, other: &Collisions) -> bool
self
and other
values to be equal, and is used
by ==
.impl Resource for Collisions
impl StructuralPartialEq for Collisions
Auto Trait Implementations§
impl Freeze for Collisions
impl RefUnwindSafe for Collisions
impl Send for Collisions
impl Sync for Collisions
impl Unpin for Collisions
impl UnwindSafe for Collisions
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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> 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>
. Box<dyn Any>
can
then be further downcast
into Box<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>
. Rc<Any>
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> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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<T> Pointable for T
impl<T> Pointable for T
source§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.