I want to destroy entities when they collide, and this is the code i use to do that.
fn do_collision(
query: Query<(Entity, &Transform, &Collider)>,
mut commands: Commands,
) {
for [(entity, transform, collider), (other_entity, other_transform, other_collider)] in
query.iter_combinations()
{
let collision = collide(
transform.translation,
collider.0,
other_transform.translation,
other_collider.0,
);
if let Some(_) = collision {
commands.entity(entity).despawn();
commands.entity(other_entity).despawn();
}
}
}
This works! But I have a slight problem, I don't want to delete the player. Instead I want to restart the game/change the state of the game. So how do I check if the entity i'm deleting has a certain component?