pub fn collision_system(
    mut interaction_event: ResMut<Events<InteractionEvent>>,
    mut wall_query: Query<(Entity, &Transform, &Size, &InteractableType)>,
    mut moveables: Query<(Entity, Mutated<Transform>)>,
) {
    for (mov_entity, move_translation) in &mut moveables.iter() {
        //println!("checking colision move: {:?}", *move_translation);
        for (destination_entity, tile_translation, size, interact_type) in
            &mut wall_query.iter()
        {
            //println!("Tile: {:?} {:?}", tile_translation, size);
            if *interact_type == InteractableType::None {
                continue;
            }
            if mov_entity == destination_entity {
                continue;
            }

            //println!("checking colision tile: {:?}", tile_translation);
            let collision = collide(
                move_translation.translation(),
                Vec2::new(8., 16.) * move_translation.scale().truncate(),
                Vec3::new(
                    tile_translation.translation().x() + (size.width/2.), 
                    tile_translation.translation().y(), 0.),
                Vec2::new(size.width, size.height)
            );

            if let Some(collision) = collision {
                //println!("Collision detected {}", move_translation.translation());
                match collision {
                    _ => interaction_event.send(InteractionEvent {
                        source: mov_entity,
                        destination: destination_entity,
                        interaction_type: InteractionType::Collision,
                    }),
                }
            }
        }
    }
}
/// Collision System
/// This system sends an event whenever two Interactables touch.
Collision System
This system sends an event whenever two Interactables touch.
Collision System This system sends an event whenever two Interactables touch .
pub fn collision_system(
    mut interaction_event: ResMut<Events<InteractionEvent>>,
    mut wall_query: Query<(Entity, &Transform, &Size, &InteractableType)>,
    mut moveables: Query<(Entity, Mutated<Transform>)>,
) {
    for (mov_entity, move_translation) in &mut moveables.iter() {
        //println!("checking colision move: {:?}", *move_translation);
        for (destination_entity, tile_translation, size, interact_type) in
            &mut wall_query.iter()
        {
            //println!("Tile: {:?} {:?}", tile_translation, size);
            if *interact_type == InteractableType::None {
                continue;
            }
            if mov_entity == destination_entity {
                continue;
            }
            //println!("checking colision tile: {:?}", tile_translation);
            let collision = collide(
                move_translation.translation(),
                Vec2::new(8., 16.) * move_translation.scale().truncate(),
                Vec3::new(
                    tile_translation.translation().x() + (size.width/2.), 
                    tile_translation.translation().y(), 0.),
                Vec2::new(size.width, size.height)
            );
            if let Some(collision) = collision {
                //println!("Collision detected {}", move_translation.translation());
                match collision {
                    _ => interaction_event.send(InteractionEvent {
                        source: mov_entity,
                        destination: destination_entity,
                        interaction_type: InteractionType::Collision,
                    }),
                }
            }
        }
    }
}
pub fn collision_system ( mut interaction_event : ResMut < Events < InteractionEvent > > , mut wall_query : Query < ( Entity , & Transform , & Size , & InteractableType ) > , mut moveables : Query < ( Entity , Mutated < Transform > ) > , ) { for ( mov_entity , move_translation ) in & mut moveables . iter ( ) { //println!("checking colision move: {:?}", *move_translation); for ( destination_entity , tile_translation , size , interact_type ) in & mut wall_query . iter ( ) { //println!("Tile: {:?} {:?}", tile_translation, size); if * interact_type == InteractableType :: None { continue ; } if mov_entity == destination_entity { continue ; } //println!("checking colision tile: {:?}", tile_translation); let collision = collide ( move_translation . translation ( ) , Vec2 :: new ( 8. , 16. ) * move_translation . scale ( ) . truncate ( ) , Vec3 :: new ( tile_translation . translation ( ) . x ( ) + ( size . width / 2. ) , tile_translation . translation ( ) . y ( ) , 0. ) , Vec2 :: new ( size . width , size . height ) ) ; if let Some ( collision ) = collision { //println!("Collision detected {}", move_translation.translation()); match collision { _ => interaction_event . send ( InteractionEvent { source : mov_entity , destination : destination_entity , interaction_type : InteractionType :: Collision , } ) , } } } } }
Collision System
This system sends an event whenever two Interactables touch.
Collision System This system sends an event whenever two Interactables touch .
interaction_event
ResMut<Events<InteractionEvent>>
wall_query
Query<(Entity, &Transform, &Size, &InteractableType)>
moveables
Query<(Entity, Mutated<Transform>)>
interaction_event
ResMut<Events<InteractionEvent>>
wall_query
Query<(Entity, &Transform, &Size, &InteractableType)>
moveables
Query<(Entity, Mutated<Transform>)>