diff --git a/src/actor.rs b/src/actor.rs index db833b6..783df2a 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -130,6 +130,7 @@ impl Default for ExperiencesGForce { fn default() -> Self { Self { }}} #[derive(Component)] pub struct Player; // Attached to the suit of the player +#[derive(Component)] pub struct PlayerCollider; // Attached to the collider of the suit of the player #[derive(Component)] pub struct PlayerDrivesThis; // Attached to the entered vehicle #[derive(Component)] pub struct PlayerCamera; // Attached to the actor to use as point of view #[derive(Component)] pub struct JustNowEnteredVehicle; @@ -390,7 +391,7 @@ pub fn handle_vehicle_enter_exit( fn handle_collisions( mut collision_event_reader: EventReader, mut ew_sfx: EventWriter, - q_player: Query<(Entity, Option<&Player>), With>, + q_player: Query<(Entity, Option<&Player>), With>, mut q_player_lifeform: Query<(&mut LifeForm, &mut Suit), With>, ) { if let (Ok((player, player_maybe)), Ok((mut lifeform, mut suit))) = (q_player.get_single(), q_player_lifeform.get_single_mut()) { diff --git a/src/commands.rs b/src/commands.rs index 8a4cd3b..368e318 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -26,6 +26,7 @@ impl Plugin for CommandsPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, load_defs); app.add_systems(Update, spawn_entities); + app.add_systems(Update, process_mesh); app.add_systems(PreUpdate, hide_colliders .run_if(any_with_component::)); app.add_event::(); @@ -842,3 +843,31 @@ pub fn hide_colliders(mut q_mesh: Query<(&mut Visibility, &Name), (Added>>, + q_parents: Query<(Option<&Parent>, Option<&actor::Player>)>, +) { + // Add "PlayerCollider" component to the player's collider mesh entity + for (child_entity, child_name, child_parent) in &mut q_mesh { + if child_name.as_str() == "Collider" { + // get the root parent + let mut get_parent = q_parents.get(child_parent.get()); + while let Ok((parent_maybe, _)) = get_parent { + if let Some(parent) = parent_maybe { + get_parent = q_parents.get(parent.get()); + } else { + break; + } + } + + // If the root parent is the player, add PlayerCollider to the collider mesh + if let Ok((_, player)) = get_parent { + if player.is_some() { + commands.entity(child_entity).insert(actor::PlayerCollider); + } + } + } + } +}