#Collision Detection minor language issue

8 messages · Page 1 of 1 (latest)

formal jackal
#
fn collision_system(mut query: Query<(&mut Velocity, &mut Transform), With<Contributor>>) 
{
    for (idx, ( l_velocity,  l_transform)) in query.iter_mut().enumerate()
    {
        for ( r_velocity, r_transform) in query.iter_mut().skip(idx+1)  // dont check for collisions twice
        {
            // Check for collision here
            }
        }
    }
}

Ive been playing around with the examples and I wanted to make two objects collide but I dont know how I would resolve the double mut borrow here

#

first didnt want to post this here because this isnt specifically a bevy issue but other people in a rust discord couldnt help me with it

#

also have a minimal example

pub fn main()
{
    let mut vec = vec![1, 2, 3, 4, 5];
    for (idx, elem) in vec.iter_mut().enumerate()
    {
        println!("{}:", elem);
        for following in vec.iter_mut().skip(idx+1)
        {
            println!("is followed by {}", following);
            *following += 1;
            *elem += 1;
        }
    }
}

I just cant index Queries ofc like I could vectors

oblique pewter
#

Query::get_many_mut 😄

#

Or iter_combinations here

#

The general purpose escape hatch is to clone though

formal jackal
#

god bless I can look those things up thank you

oblique pewter
#

Merry Christmas 😉