bevy_two_entities
A tiny crate offering a few convenience traits on Bevy's Query
and (&Query, &Query)
for scenarios involving exactly two entities.
Examples
fn game_over(
collisions: Query<&Collision>,
players: Query<(), With<Player>>,
enemies: Query<(), With<Enemy>>,
mut next_state: ResMut<NextState<GameState>>,
) {
for collision in &collisions {
if (&players, &enemies).both(collision.0, collision.1) {
next_state.set(GameState::GameOver);
}
}
}
fn damage_enemy(
collisions: Query<&Collision>,
players: Query<(), With<Player>>,
mut enemies: Query<&mut HitPoints, With<Enemy>>,
) {
for collision in &collisions {
let mut queries = (&players, &mut enemies);
let Some((_, mut enemy_hp)) = queries.get_both_mut(collision.0, collision.1) else {
continue;
};
enemy_hp.0 -= 1;
}
}
Compatibility
bevy_two_entities |
bevy |
0.2 |
0.14 |
0.1 |
0.13 |