How can you detect collision among one group of objects? (2d) #5873
-
I have a component that may collide with other components of the same type. I can detect this by doing a nested |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
You may want to look at the rapier Plugin for bevy. It also has physics simulation, but you can use just the collision detection |
Beta Was this translation helpful? Give feedback.
-
I'll look into Rapier. Is there no other way? I was thinking something with |
Beta Was this translation helpful? Give feedback.
-
It sounds like the question isn't so much about collision detection as it is about conflicting queries. If you need multiple queries sharing mutable borrows to the same component type, you need a mut queries: ParamSet<(
Query<&mut Text, With<HeroProficiencyDisplay>>,
Query<&mut Text, With<HeroDamageResDisplay>>,
)>, if let Ok(mut text) = query.p0().get_single_mut() {}
if let Ok(mut text) = query.p1().get_single_mut() {} Note that you still cannot use these queries at the same time, because that would be potentially unsafe. Instead, you could perhaps use your first query to retrieve the entity that is being collided with, return it from the iterator through a |
Beta Was this translation helpful? Give feedback.
-
Prehaps fn rain(
mut query_rain: Query<(Entity, &mut Transform, &mut Sprite), With<Rain>>,
query_objs: Query<(Entity, &Transform, &Sprite), Without<Rain>>,
) {
let mut iter = query_rain.iter_combinations_mut();
while let Some([mut rain_drop_a, mut rain_drop_b]) = iter.fetch_next() {
// Handle collisions between entities with Rain.
}
for mut rain_drop in &mut query_rain {
for item in &query_objs {
// Handle collisions with entities without Rain.
}
}
} |
Beta Was this translation helpful? Give feedback.
Prehaps
iter_combinations_mut
is what you're looking for.