Skip to content

How can you detect collision among one group of objects? (2d) #5873

Answered by tim-blackbird
visualcode-t asked this question in Q&A
Discussion options

You must be logged in to vote

Prehaps iter_combinations_mut is what you're looking for.

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.
        }
    }
}

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Sheepyhead
Comment options

Comment options

You must be logged in to vote
2 replies
@visualcode-t
Comment options

@Jazarro
Comment options

Comment options

You must be logged in to vote
1 reply
@visualcode-t
Comment options

Answer selected by visualcode-t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants