fix flashlight when in vehicles

This commit is contained in:
yuni 2024-07-14 21:07:00 +02:00
parent 534a313e21
commit ed0641d68e
2 changed files with 13 additions and 6 deletions

View file

@ -428,11 +428,10 @@ pub fn handle_input(
pub fn handle_vehicle_enter_exit(
mut commands: Commands,
mut settings: ResMut<Settings>,
mut er_vehicle: EventReader<VehicleEnterExitEvent>,
mut ew_achievement: EventWriter<game::AchievementEvent>,
mut q_playerflashlight: Query<
&mut Visibility,
&mut Transform,
(
With<PlayersFlashLight>,
Without<ActorVehicleBeingEntered>,
@ -477,9 +476,9 @@ pub fn handle_vehicle_enter_exit(
commands.entity(vehicle).remove::<hud::IsTargeted>();
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::<PlayerCamera>();

View file

@ -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