From 17e7879777226212f00e898d2aa3ada21c3a2e00 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 9 Dec 2021 15:16:16 +0000 Subject: [PATCH] Added surface traction factor --- common/src/states/utils.rs | 4 ++-- common/src/terrain/block.rs | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 0470964555..c567d46769 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -307,7 +307,7 @@ fn basic_move(data: &JoinData<'_>, update: &mut StateUpdate, efficiency: f32) { let accel = if let Some(block) = data.physics.on_ground { // FRIC_GROUND temporarily used to normalize things around expected values - data.body.base_accel() * block.get_friction() / FRIC_GROUND + data.body.base_accel() * block.get_traction() * block.get_friction() / FRIC_GROUND } else { data.body.air_accel() } * efficiency; @@ -354,7 +354,7 @@ pub fn handle_forced_movement( let strength = strength * data.stats.move_speed_modifier * data.stats.friction_modifier; if let Some(accel) = data.physics.on_ground.map(|block| { // FRIC_GROUND temporarily used to normalize things around expected values - data.body.base_accel() * block.get_friction() / FRIC_GROUND + data.body.base_accel() * block.get_traction() * block.get_friction() / FRIC_GROUND }) { update.vel.0 += Vec2::broadcast(data.dt.0) * accel diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 9eb1049535..1bad97490a 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -312,7 +312,8 @@ impl Block { .unwrap_or(1.0) } - // Used to calculate surface friction when walking. Currently has no units. + /// Get the friction constant used to calculate surface friction when + /// walking/climbing. Currently has no units. #[inline] pub fn get_friction(&self) -> f32 { match self.kind() { @@ -321,6 +322,19 @@ impl Block { } } + /// Get the traction permitted by this block as a proportion of the friction + /// applied. + /// + /// 1.0 = default, 0.0 = completely inhibits movement, > 1.0 = potential for + /// infinite acceleration (in a vacuum). + #[inline] + pub fn get_traction(&self) -> f32 { + match self.kind() { + BlockKind::Snow => 0.8, + _ => 1.0, + } + } + #[inline] pub fn kind(&self) -> BlockKind { self.kind }