From 919b8018322f84108421b5ba88cfa732c5862c49 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 17 Apr 2024 13:55:39 +0200 Subject: [PATCH] fix dying from entering vehicles --- src/actor.rs | 2 ++ src/camera.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index fc71686..564c935 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -110,6 +110,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 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; #[derive(Component)] pub struct ActorEnteringVehicle; #[derive(Component)] pub struct ActorVehicleBeingEntered; #[derive(Component)] pub struct WantsMaxRotation(pub f64); @@ -326,6 +327,7 @@ pub fn handle_vehicle_enter_exit( ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle)); commands.entity(driver).remove::(); commands.entity(driver).remove::(); + commands.entity(driver).insert(JustNowEnteredVehicle); commands.entity(vehicle).insert(PlayerCamera); commands.entity(vehicle).insert(PlayerDrivesThis); } diff --git a/src/camera.rs b/src/camera.rs index 3787fcc..87dc1bf 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -129,9 +129,10 @@ pub fn handle_input( } fn manage_player_actor( + mut commands: Commands, settings: Res, mut q_playercam: Query<&mut Visibility, With>, - mut q_hiddenplayer: Query<(&mut Visibility, &mut Position, &mut Rotation, &mut LinearVelocity, &mut AngularVelocity), (With, Without)>, + mut q_hiddenplayer: Query<(Entity, &mut Visibility, &mut Position, &mut Rotation, &mut LinearVelocity, &mut AngularVelocity, Option<&mut actor::ExperiencesGForce>, Option<&actor::JustNowEnteredVehicle>), (With, Without)>, q_ride: Query<(&Transform, &Position, &Rotation, &LinearVelocity, &AngularVelocity), (With, Without)>, ) { for mut vis in &mut q_playercam { @@ -142,7 +143,7 @@ fn manage_player_actor( *vis = Visibility::Hidden; } } - for (mut vis, mut pos, mut rot, mut v, mut angv) in &mut q_hiddenplayer { + for (entity, mut vis, mut pos, mut rot, mut v, mut angv, mut gforce, entering) in &mut q_hiddenplayer { // If we are riding a vehicle, place the player at the position where // it would be after exiting the vehicle. // I would rather place it in the center of the vehicle, but at the time @@ -154,6 +155,13 @@ fn manage_player_actor( rot.0 = ride_rot.0 * DQuat::from_array([-1.0, 0.0, 0.0, 0.0]); *v = ride_v.clone(); *angv = ride_angv.clone(); + + // I really don't want people to die from the g-forces of entering + // vehicles at high relative speed, even though they probably should. + if let (Some(gforce), Some(_)) = (&mut gforce, entering) { + gforce.last_linear_velocity = v.0; + commands.entity(entity).remove::(); + } } } }