From 02af3843b695857e9832434336cf093968f00ff5 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 19 Sep 2024 20:41:33 +0200 Subject: update movement code everywhere --- client/player/controllable_player.gd | 2 +- server/protocol/src/movement.rs | 7 +++++-- test-client/movement.ts | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/player/controllable_player.gd b/client/player/controllable_player.gd index 9e7ce2b2..016ee637 100644 --- a/client/player/controllable_player.gd +++ b/client/player/controllable_player.gd @@ -88,7 +88,7 @@ func _process_movement(delta): rotation_anim = rotation_ func update(dt: float, boost: bool): - direction = direction.limit_length(1.); + direction = direction.limit_length(1.) if direction.length() > 0.05: self.facing = direction + (self.facing - direction) * exp(-dt * 10.) if direction.length() < 0.5: diff --git a/server/protocol/src/movement.rs b/server/protocol/src/movement.rs index ebcc627d..85accb31 100644 --- a/server/protocol/src/movement.rs +++ b/server/protocol/src/movement.rs @@ -58,10 +58,13 @@ impl MovementBase { } pub fn update(&mut self, map: &HashSet, dt: f32) { let mut boost = self.input_boost; - let direction = self.input_direction.clamp_length_max(1.); - if direction.length() > 0.1 { + let mut direction = self.input_direction.clamp_length_max(1.); + if direction.length() > 0.05 { self.facing = direction + (self.facing - direction) * (-dt * 10.).exp(); } + if direction.length() < 0.5 { + direction *= 0.; + } self.rotation = self.facing.x.atan2(self.facing.y); boost &= direction.length() > 0.1; self.boosting = boost && (self.boosting || self.stamina >= 1.) && self.stamina > 0.; diff --git a/test-client/movement.ts b/test-client/movement.ts index 62846edf..7d395396 100644 --- a/test-client/movement.ts +++ b/test-client/movement.ts @@ -37,7 +37,8 @@ export interface MovementBase { } export function update_movement(p: MovementBase, dt: number, direction: V2, boost: boolean) { - if (length(direction) > 0.1) lerp_exp_v2_mut(p.facing, direction, dt * 10.) + if (length(direction) > 0.05) lerp_exp_v2_mut(p.facing, direction, dt * 10.) + if (length(direction) < 0.5) direction.x = direction.y = 0 p.rot = Math.atan2(p.facing.x, p.facing.y) boost &&= length(direction) > 0.1 p.boosting = boost && (p.boosting || p.stamina >= 1) && p.stamina > 0 -- cgit v1.2.3-70-g09d2