From 962f73f522bc5c7140f9779c850db009b5ccac3a Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 30 Mar 2024 18:05:22 +0100 Subject: [PATCH] stop physics simulation of original model when entering vehicle --- src/actor.rs | 21 ++++++++++----------- src/camera.rs | 4 ---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 4490f65..af61e59 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -295,37 +295,35 @@ pub fn handle_input( pub fn handle_vehicle_enter_exit( mut commands: Commands, mut er_vehicle: EventReader, - mut q_drivers: Query<(Entity, &mut Actor, &mut Visibility, &mut Transform), (Without, With)>, - mut q_vehicles: Query<(Entity, &mut Actor, &mut Visibility, &mut Transform), (With, Without)>, + mut q_drivers: Query<(Entity, &mut Visibility, &mut Transform), (Without, With)>, + mut q_vehicles: Query<(Entity, &mut Visibility, &mut Transform), (With, Without)>, mut ew_sfx: EventWriter, ) { for event in er_vehicle.read() { - for (driver, mut driver_actor, mut driver_vis, mut driver_trans) in q_drivers.iter_mut() { + for (driver, mut driver_vis, mut driver_trans) in q_drivers.iter_mut() { if driver == event.driver { - for (vehicle, mut vehicle_actor, mut vehicle_vis, mut vehicle_trans) in q_vehicles.iter_mut() { + for (vehicle, mut vehicle_vis, vehicle_trans) in q_vehicles.iter_mut() { if vehicle == event.vehicle { if event.is_entering { // Entering Vehicle *driver_vis = Visibility::Hidden; if event.is_player { ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle)); - //player_actor.inside_entity = entity.index(); - *vehicle_vis = Visibility::Hidden; - driver_actor.v = vehicle_actor.v; + //*vehicle_vis = Visibility::Hidden; commands.entity(driver).remove::(); commands.entity(vehicle).insert(PlayerCamera); commands.entity(vehicle).insert(PlayerDrivesThis); + commands.entity(driver).remove::(); } } else { // Exiting Vehicle - *driver_vis = Visibility::Inherited; if event.is_player { ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); *vehicle_vis = Visibility::Inherited; - vehicle_actor.v = driver_actor.v; - vehicle_actor.angular_momentum = driver_actor.angular_momentum; - *vehicle_trans = driver_trans.clone(); + // TODO: set actor momentum to vehicle momentum (linear/angular) + commands.entity(driver).insert(RigidBody::Dynamic); + commands.entity(vehicle).remove::(); commands.entity(driver).insert(PlayerCamera); commands.entity(vehicle).remove::(); @@ -333,6 +331,7 @@ pub fn handle_vehicle_enter_exit( else { *driver_trans = vehicle_trans.clone(); } + driver_trans.translation = vehicle_trans.translation.clone(); } } } diff --git a/src/camera.rs b/src/camera.rs index 5cb3ba7..55f5b1f 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -94,7 +94,6 @@ pub fn handle_input( fn manage_player_actor( settings: Res, mut q_playercam: Query<&mut Visibility, With>, - mut q_hiddenplayer: Query<&mut Visibility, (With, Without)>, ) { for mut vis in &mut q_playercam { if settings.third_person { @@ -104,9 +103,6 @@ fn manage_player_actor( *vis = Visibility::Hidden; } } - for mut vis in &mut q_hiddenplayer { - *vis = Visibility::Hidden; - } } #[allow(clippy::too_many_arguments)]