From 6275a64d7c665c16f4af87e42e74018755df81d6 Mon Sep 17 00:00:00 2001 From: yuni Date: Tue, 11 Jun 2024 03:29:26 +0200 Subject: [PATCH] ignore gravity when calculating g forces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because gravity is obviously not a force, just a ✨magical✨ property of spacetime, conveyed by messenger particles called Higgs Bosons which act as force carriers for this non-force. Who made this up? :D --- src/actor.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index d6820e1..f83c529 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -30,6 +30,7 @@ impl Plugin for ActorPlugin { ( update_physics_lifeforms, update_power, + handle_gravity, handle_wants_maxrotation, handle_wants_maxvelocity.run_if(any_with_component::), handle_wants_lookat.run_if(alive), @@ -44,7 +45,6 @@ impl Plugin for ActorPlugin { app.add_systems( Update, ( - handle_gravity, handle_input.run_if(in_control), handle_collisions, handle_damage, @@ -52,16 +52,9 @@ impl Plugin for ActorPlugin { ); app.add_systems(PostUpdate, (handle_vehicle_enter_exit,)); app.add_event::(); - app.insert_resource(GravityUpdateTimer(Timer::from_seconds( - 1.0, - TimerMode::Repeating, - ))); } } -#[derive(Resource)] -pub struct GravityUpdateTimer(Timer); - #[derive(Copy, Clone)] pub enum DamageType { Unknown, @@ -126,6 +119,7 @@ pub struct ExperiencesGForce { pub visual_effect_threshold: f32, pub visual_effect: f32, pub last_linear_velocity: DVec3, + pub gravitational_component: DVec3, pub ignore_gforce_seconds: f32, } impl Default for ExperiencesGForce { @@ -135,7 +129,8 @@ impl Default for ExperiencesGForce { damage_threshold: 100.0, visual_effect_threshold: 20.0, visual_effect: 0.0, - last_linear_velocity: DVec3::splat(0.0), + last_linear_velocity: DVec3::ZERO, + gravitational_component: DVec3::ZERO, ignore_gforce_seconds: 0.01, } } @@ -650,8 +645,10 @@ fn handle_gforce( let dt = time.delta_seconds(); let factor = 1.0 / dt / nature::EARTH_GRAVITY; for (v, mut hp, mut gforce) in &mut q_actor { - gforce.gforce = factor * (v.0 - gforce.last_linear_velocity).length() as f32; + gforce.gforce = factor + * (v.0 - gforce.last_linear_velocity - gforce.gravitational_component).length() as f32; gforce.last_linear_velocity = v.0; + gforce.gravitational_component = DVec3::ZERO; if gforce.ignore_gforce_seconds > 0.0 { gforce.ignore_gforce_seconds -= dt; continue; @@ -675,18 +672,25 @@ fn handle_gforce( fn handle_gravity( time: Res