#bevy #entities #gamedev #query #traits #collision #convenience

bevy_two_entities

A few convenience traits for working with Bevy Queries

3 releases (breaking)

0.3.0 Dec 1, 2024
0.2.0 Jul 4, 2024
0.1.0 May 16, 2024

#1361 in Game dev

Download history 5/week @ 2024-09-22 1/week @ 2024-09-29 1/week @ 2024-10-06 2/week @ 2024-10-13 1/week @ 2024-10-20 4/week @ 2024-11-03 122/week @ 2024-12-01

122 downloads per month

MIT/Apache

19KB
397 lines

bevy_two_entities

crates.io docs Following released Bevy versions

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.3 0.15
0.2 0.14
0.1 0.13

Dependencies

~21–32MB
~518K SLoC