@@ -16,7 +16,7 @@ pub(crate) use forces::FloatZero;
1616pub ( crate ) use forces:: Torque ;
1717
1818use crate :: prelude:: * ;
19- use bevy:: prelude:: * ;
19+ use bevy:: { prelude:: * , utils :: HashSet } ;
2020use derive_more:: From ;
2121
2222/// A non-deformable body used for the simulation of most physics objects.
@@ -826,6 +826,63 @@ pub struct AngularDamping(pub Scalar);
826826#[ reflect( Debug , Component , Default , PartialEq ) ]
827827pub struct Dominance ( pub i8 ) ;
828828
829+ /// A component containing a set of entities for which any collisions with the
830+ /// owning entity will be ignored.
831+ ///
832+ /// ## Example
833+ ///
834+ /// ```
835+ /// use bevy::prelude::*;
836+ /// # #[cfg(feature = "2d")]
837+ /// # use avian2d::prelude::*;
838+ /// # #[cfg(feature = "3d")]
839+ /// use avian3d::prelude::*;
840+ ///
841+ /// fn setup(mut commands: Commands) {
842+ /// // Spawn an entity with a collider
843+ #[ cfg_attr(
844+ feature = "2d" ,
845+ doc = " let ent1 = commands" ,
846+ doc = " .spawn((RigidBody::Dynamic, Collider::circle(0.5)))" ,
847+ doc = " .id();"
848+ ) ]
849+ #[ cfg_attr(
850+ feature = "3d" ,
851+ doc = " let ent1 = commands" ,
852+ doc = " .spawn((RigidBody::Dynamic, Collider::sphere(0.5)))" ,
853+ doc = " .id();"
854+ ) ]
855+ ///
856+ /// // Spawn another entity with a collider and configure it to avoid collisions with the first entity.
857+ #[ cfg_attr(
858+ feature = "2d" ,
859+ doc = " let ent1 = commands.spawn((" ,
860+ doc = " RigidBody::Dynamic," ,
861+ doc = " Collider::circle(0.5)," ,
862+ doc = " IgnoredCollisions::from_iter([ent1])," ,
863+ doc = "));"
864+ ) ]
865+ #[ cfg_attr(
866+ feature = "3d" ,
867+ doc = " let ent1 = commands.spawn((" ,
868+ doc = " RigidBody::Dynamic," ,
869+ doc = " Collider::sphere(0.5)," ,
870+ doc = " IgnoredCollisions::from_iter([ent1])," ,
871+ doc = " ));"
872+ ) ]
873+ /// }
874+ /// ```
875+ ///
876+ /// See also [`CollisionLayers`].
877+ #[ derive( Component , Clone , Debug , Default , Deref , DerefMut ) ]
878+ pub struct IgnoredCollisions ( pub HashSet < Entity > ) ;
879+
880+ impl FromIterator < Entity > for IgnoredCollisions {
881+ fn from_iter < T : IntoIterator < Item = Entity > > ( iter : T ) -> Self {
882+ Self ( HashSet :: from_iter ( iter) )
883+ }
884+ }
885+
829886#[ cfg( test) ]
830887mod tests {
831888 use crate :: prelude:: * ;
0 commit comments