From 051d24bf65475e08fb7c11e258e503192c0cb52e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 5 Mar 2026 19:39:08 +0100 Subject: new movement math varies less with tick rate --- server/protocol/src/movement.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'server/protocol/src/movement.rs') diff --git a/server/protocol/src/movement.rs b/server/protocol/src/movement.rs index 14aefacb..062c250d 100644 --- a/server/protocol/src/movement.rs +++ b/server/protocol/src/movement.rs @@ -22,8 +22,8 @@ use crate::{ use std::collections::HashSet; const PLAYER_SIZE: f32 = 0.4; -const PLAYER_FRICTION: f32 = 15.0; -const PLAYER_SPEED: f32 = 55.0; +const PLAYER_ACCELERATION: f32 = 10.0; +const PLAYER_SPEED: f32 = 3.8; const BOOST_FACTOR: f32 = 2.5; const BOOST_DURATION: f32 = 0.3; const BOOST_RESTORE: f32 = 0.5; @@ -74,10 +74,9 @@ impl MovementBase { dt / BOOST_RESTORE }; self.stamina = self.stamina.clamp(0., 1.); - let speed = PLAYER_SPEED * if self.boosting { BOOST_FACTOR } else { 1. }; - self.velocity += direction * dt * speed; + let target_v = direction * (PLAYER_SPEED * if self.boosting { BOOST_FACTOR } else { 1. }); + self.velocity = target_v + (self.velocity - target_v) * (-dt * PLAYER_ACCELERATION).exp(); self.position += self.velocity * dt; - self.velocity *= (-dt * PLAYER_FRICTION).exp(); collide_player_tiles(self, map); } -- cgit v1.3