@@ -20,7 +20,7 @@ pub(crate) use forces::FloatZero;
2020pub ( crate ) use forces:: Torque ;
2121
2222use crate :: prelude:: * ;
23- use bevy:: prelude:: * ;
23+ use bevy:: { prelude:: * , utils :: HashSet } ;
2424use derive_more:: From ;
2525
2626/// A non-deformable body used for the simulation of most physics objects.
@@ -684,3 +684,60 @@ pub struct AngularDamping(pub Scalar);
684684#[ cfg_attr( feature = "serialize" , reflect( Serialize , Deserialize ) ) ]
685685#[ reflect( Debug , Component , Default , PartialEq ) ]
686686pub struct Dominance ( pub i8 ) ;
687+
688+ /// A component containing a set of entities for which any collisions with the
689+ /// owning entity will be ignored.
690+ ///
691+ /// ## Example
692+ ///
693+ /// ```
694+ /// use bevy::prelude::*;
695+ /// # #[cfg(feature = "2d")]
696+ /// # use avian2d::prelude::*;
697+ /// # #[cfg(feature = "3d")]
698+ /// use avian3d::prelude::*;
699+ ///
700+ /// fn setup(mut commands: Commands) {
701+ /// // Spawn an entity with a collider
702+ #[ cfg_attr(
703+ feature = "2d" ,
704+ doc = " let ent1 = commands" ,
705+ doc = " .spawn((RigidBody::Dynamic, Collider::circle(0.5)))" ,
706+ doc = " .id();"
707+ ) ]
708+ #[ cfg_attr(
709+ feature = "3d" ,
710+ doc = " let ent1 = commands" ,
711+ doc = " .spawn((RigidBody::Dynamic, Collider::sphere(0.5)))" ,
712+ doc = " .id();"
713+ ) ]
714+ ///
715+ /// // Spawn another entity with a collider and configure it to avoid collisions with the first entity.
716+ #[ cfg_attr(
717+ feature = "2d" ,
718+ doc = " let ent1 = commands.spawn((" ,
719+ doc = " RigidBody::Dynamic," ,
720+ doc = " Collider::circle(0.5)," ,
721+ doc = " IgnoredCollisions::from_iter([ent1])," ,
722+ doc = "));"
723+ ) ]
724+ #[ cfg_attr(
725+ feature = "3d" ,
726+ doc = " let ent1 = commands.spawn((" ,
727+ doc = " RigidBody::Dynamic," ,
728+ doc = " Collider::sphere(0.5)," ,
729+ doc = " IgnoredCollisions::from_iter([ent1])," ,
730+ doc = " ));"
731+ ) ]
732+ /// }
733+ /// ```
734+ ///
735+ /// See also [`CollisionLayers`].
736+ #[ derive( Component , Clone , Debug , Default , Deref , DerefMut ) ]
737+ pub struct IgnoredCollisions ( pub HashSet < Entity > ) ;
738+
739+ impl FromIterator < Entity > for IgnoredCollisions {
740+ fn from_iter < T : IntoIterator < Item = Entity > > ( iter : T ) -> Self {
741+ Self ( HashSet :: from_iter ( iter) )
742+ }
743+ }
0 commit comments