Skip to content
Discussion options

You must be logged in to vote

Bevy provides the iter_combinations_mut method. You should use it.

iter_combinations_mut basically exists for this exact use-case. Otherwise it would be impossible to do what you are doing.

Check the following example for some ready-made code:

fn interact_bodies(mut query: Query<(&Mass, &GlobalTransform, &mut Acceleration)>) {
let mut iter = query.iter_combinations_mut();
while let Some([(Mass(m1), transform1, mut acc1), (Mass(m2), transform2, mut acc2)]) =
iter.fetch_next()
{
let delta = transform2.translation() - transform1.translation();
let distance_sq: f32 = delta.length_squared(

Replies: 1 comment 1 reply

Comment options

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

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