From 1f1d9c5625b3907a8a23a55cfc023b0c02facc6a Mon Sep 17 00:00:00 2001 From: Treeco <5021038-Treeco@users.noreply.gitlab.com> Date: Thu, 9 Jul 2020 15:46:00 +0100 Subject: [PATCH 1/2] Reset rather than accumulate velocity when stuck or in unloaded chunks --- common/src/sys/phys.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index d57ef92df1..560adeb196 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -134,6 +134,7 @@ impl<'a> System<'a> for Sys { let dt_lerp = 0.2; (vel.0 * dt_lerp + old_vel.0 * (1.0 - dt_lerp)) * dt.0 } else { + vel.0 = Vec3::zero(); Vec3::zero() }; @@ -319,6 +320,7 @@ impl<'a> System<'a> for Sys { } if attempts == MAX_ATTEMPTS { + vel.0 = Vec3::zero(); pos.0 = old_pos; break; } From c7e8a6bfaea65edf05fa9b1d3fc36e529fd58ec5 Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 18 Jul 2020 07:08:38 -0400 Subject: [PATCH 2/2] Remove gravity rather than reset velocity in unloaded chunks --- common/src/sys/phys.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 560adeb196..29242556d4 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -117,7 +117,12 @@ impl<'a> System<'a> for Sys { } else { 0.0 }); - let downward_force = if physics_state.in_fluid { + let in_loaded_chunk = terrain + .get_key(terrain.pos_key(pos.0.map(|e| e.floor() as i32))) + .is_some(); + let downward_force = if !in_loaded_chunk { + 0.0 // No gravity in unloaded chunks + } else if physics_state.in_fluid { (1.0 - BOUYANCY) * GRAVITY } else { GRAVITY @@ -125,16 +130,12 @@ impl<'a> System<'a> for Sys { vel.0 = integrate_forces(dt.0, vel.0, downward_force, friction); // Don't move if we're not in a loaded chunk - let mut pos_delta = if terrain - .get_key(terrain.pos_key(pos.0.map(|e| e.floor() as i32))) - .is_some() - { + let mut pos_delta = if in_loaded_chunk { // this is an approximation that allows most framerates to // behave in a similar manner. let dt_lerp = 0.2; (vel.0 * dt_lerp + old_vel.0 * (1.0 - dt_lerp)) * dt.0 } else { - vel.0 = Vec3::zero(); Vec3::zero() };