From ed0641d68ec8f4cf23d979120e1441ea061e25a2 Mon Sep 17 00:00:00 2001 From: yuni Date: Sun, 14 Jul 2024 21:07:00 +0200 Subject: [PATCH] fix flashlight when in vehicles --- src/actor.rs | 13 ++++++++----- src/camera.rs | 6 +++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index fa33e1a..2995490 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -428,11 +428,10 @@ pub fn handle_input( pub fn handle_vehicle_enter_exit( mut commands: Commands, - mut settings: ResMut, mut er_vehicle: EventReader, mut ew_achievement: EventWriter, mut q_playerflashlight: Query< - &mut Visibility, + &mut Transform, ( With, Without, @@ -477,9 +476,9 @@ pub fn handle_vehicle_enter_exit( commands.entity(vehicle).remove::(); commands.entity(vehicle).insert(PlayerCamera); commands.entity(vehicle).insert(PlayerDrivesThis); - if let Ok(mut flashlight_vis) = q_playerflashlight.get_single_mut() { - *flashlight_vis = Visibility::Hidden; - settings.flashlight_active = false; + if let Ok(mut flashlight_trans) = q_playerflashlight.get_single_mut() { + flashlight_trans.rotation = Quat::from_rotation_y(0f32); + flashlight_trans.translation = Vec3::new(0.0, 0.0, 0.0); } if let Some(vehicle_name) = &event.name { ew_achievement.send(game::AchievementEvent::RideVehicle( @@ -491,6 +490,10 @@ pub fn handle_vehicle_enter_exit( if let Some(collider) = &vehicle_component.stored_drivers_collider { commands.entity(driver).insert(collider.clone()); } + if let Ok(mut flashlight_trans) = q_playerflashlight.get_single_mut() { + flashlight_trans.rotation = Quat::from_rotation_y(180f32.to_radians()); + flashlight_trans.translation = Vec3::new(0.0, 0.0, 1.0); + } commands.entity(driver).insert(RigidBody::Dynamic); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); commands.entity(vehicle).remove::(); diff --git a/src/camera.rs b/src/camera.rs index 472bd14..1e1456e 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -34,7 +34,11 @@ impl Plugin for CameraPlugin { app.add_systems(Startup, setup_camera); app.add_systems(Update, handle_input.run_if(in_control)); app.add_systems(Update, update_map_only_object_visibility.run_if(alive)); - app.add_systems(Update, manage_player_actor.after(handle_input)); + app.add_systems( + PostUpdate, + manage_player_actor + .in_set(sync::SyncSet::PositionToTransform), + ); app.add_systems( PostUpdate, sync_camera_to_player