#Aabb2d - collisiton detection for two sprites

6 messages · Page 1 of 1 (latest)

jolly prawn
#

The following sysetem results in this error message:

"Transform in a way that conflicts with a previous system parameter. Consider using Without<T> to create disjoint Queries or merging conflicting Queries into a ParamSet."

I do not understand, why the quieries are conflicting:

fn check_for_collisions(
    mut commands: Commands,
    mut maus_query: Query<(Entity, &Transform), With<Mausi>>,
    mut schnecke_query: Query<&mut Transform, With<Schnecke>>,
    mut collision_events: EventWriter<CollisionEvent>,
) {
    for (maus_entity, maus_transform) in maus_query.iter_mut() {
        let mausi_aabb = Aabb2d::new(
            maus_transform.translation.truncate(),
            maus_transform.scale.truncate() / 2.,
        );

        for schnecke_transform in schnecke_query.iter_mut() {
            let schnecke_aabb = Aabb2d::new(
                schnecke_transform.translation.truncate(),
                schnecke_transform.scale.truncate() / 2.,
            );

            if schnecke_aabb.intersects(&mausi_aabb) {
                println!("Collision detected!");
                collision_events.send_default();
                commands.entity(maus_entity).despawn();
            }
        }
    }
}

Any idea/help? Thanks a lot.

green lava
#

an entity may be matched by both queries, which would mean you’d have a &Transform and a &mut Transform from the same entity at the same time

#

and that’d be against rust’s rules

#

so you need to use a Without filter to make sure the same entity can never match both queries

jolly prawn
#

thanks - assuming I have two systems using the same query, is that not possible?

fn move_schnecke(mut query: Query<&mut Transform, With<Schnecke>>, time: Res<Time>)

and

fn check_for_collisions( mut commands: Commands, mut maus_query: Query<(Entity, &Transform), With<Mausi>>, mut schnecke_query: Query<&mut Transform, With<Schnecke>>, mut collision_events: EventWriter<CollisionEvent>, )

jolly prawn
#

I changed mut schnecke_query: Query<&mut Transform, With<Schnecke>>, to mut schnecke_query: Query<&Transform, With<Schnecke>>, Now the code runs without crashing, but the Aabb2d colliston detection does still not work as intended.