fix collision sounds
This commit is contained in:
parent
f9fcb885fa
commit
79673e5ec5
|
@ -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 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 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 PlayerCamera; // Attached to the actor to use as point of view
|
||||||
#[derive(Component)] pub struct JustNowEnteredVehicle;
|
#[derive(Component)] pub struct JustNowEnteredVehicle;
|
||||||
|
@ -390,7 +391,7 @@ pub fn handle_vehicle_enter_exit(
|
||||||
fn handle_collisions(
|
fn handle_collisions(
|
||||||
mut collision_event_reader: EventReader<CollisionStarted>,
|
mut collision_event_reader: EventReader<CollisionStarted>,
|
||||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
q_player: Query<(Entity, Option<&Player>), With<PlayerCamera>>,
|
q_player: Query<(Entity, Option<&Player>), With<PlayerCollider>>,
|
||||||
mut q_player_lifeform: Query<(&mut LifeForm, &mut Suit), With<Player>>,
|
mut q_player_lifeform: Query<(&mut LifeForm, &mut Suit), With<Player>>,
|
||||||
) {
|
) {
|
||||||
if let (Ok((player, player_maybe)), Ok((mut lifeform, mut suit))) = (q_player.get_single(), q_player_lifeform.get_single_mut()) {
|
if let (Ok((player, player_maybe)), Ok((mut lifeform, mut suit))) = (q_player.get_single(), q_player_lifeform.get_single_mut()) {
|
||||||
|
|
|
@ -26,6 +26,7 @@ impl Plugin for CommandsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, load_defs);
|
app.add_systems(Startup, load_defs);
|
||||||
app.add_systems(Update, spawn_entities);
|
app.add_systems(Update, spawn_entities);
|
||||||
|
app.add_systems(Update, process_mesh);
|
||||||
app.add_systems(PreUpdate, hide_colliders
|
app.add_systems(PreUpdate, hide_colliders
|
||||||
.run_if(any_with_component::<NeedsSceneColliderRemoved>));
|
.run_if(any_with_component::<NeedsSceneColliderRemoved>));
|
||||||
app.add_event::<SpawnEvent>();
|
app.add_event::<SpawnEvent>();
|
||||||
|
@ -842,3 +843,31 @@ pub fn hide_colliders(mut q_mesh: Query<(&mut Visibility, &Name), (Added<Visibil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process_mesh(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut q_mesh: Query<(Entity, &Name, &Parent), Added<Handle<Mesh>>>,
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue