aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-03-05 19:39:08 +0100
committermetamuffin <metamuffin@disroot.org>2026-03-05 19:39:08 +0100
commit051d24bf65475e08fb7c11e258e503192c0cb52e (patch)
tree068c730523f8d0009c36e0590a2bb83f85b5857e
parente1dc33a6923a840953b8da5fb9f6eac30ff05f28 (diff)
downloadhurrycurry-051d24bf65475e08fb7c11e258e503192c0cb52e.tar
hurrycurry-051d24bf65475e08fb7c11e258e503192c0cb52e.tar.bz2
hurrycurry-051d24bf65475e08fb7c11e258e503192c0cb52e.tar.zst
new movement math varies less with tick rate
-rw-r--r--client/player/player.gd9
-rw-r--r--server/protocol/src/movement.rs9
-rw-r--r--test-client/movement.ts8
3 files changed, 11 insertions, 15 deletions
diff --git a/client/player/player.gd b/client/player/player.gd
index dd705423..a72104b5 100644
--- a/client/player/player.gd
+++ b/client/player/player.gd
@@ -21,8 +21,8 @@ const ITEM_BUBBLE: PackedScene = preload("res://player/item_bubble.tscn")
const EFFECT: PackedScene = preload("res://player/particles/effect.tscn")
const PLAYER_SIZE: float = 0.4
-const PLAYER_SPEED = 55
-const PLAYER_FRICTION = 15
+const PLAYER_ACCELERATION = 10
+const PLAYER_SPEED = 3.8
const BOOST_FACTOR = 2.5
const BOOST_DURATION = 0.3
const BOOST_RESTORE = 0.5
@@ -145,10 +145,9 @@ func update_movement(dt: float, boost: bool):
if boosting: stamina -= dt / BOOST_DURATION
else: stamina += dt / BOOST_RESTORE
stamina = max(min(stamina, 1.0), 0.0)
- var speed = PLAYER_SPEED * (BOOST_FACTOR if boosting else 1.)
- velocity_ += direction * dt * speed
+ var target_v = direction * PLAYER_SPEED * (BOOST_FACTOR if boosting else 1.)
+ velocity_ = target_v + (velocity_ - target_v) * exp(-dt * PLAYER_ACCELERATION)
position_ += velocity_ * dt
- velocity_ = velocity_ * exp(-dt * PLAYER_FRICTION)
collide(dt)
func collide(dt: float):
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);
}
diff --git a/test-client/movement.ts b/test-client/movement.ts
index 394f741e..7c320b5f 100644
--- a/test-client/movement.ts
+++ b/test-client/movement.ts
@@ -20,8 +20,8 @@ import { tiles } from "./main.ts";
import { V2, normalize, length, sub_v2, lerp_exp_v2_mut } from "./util.ts";
export const PLAYER_SIZE = 0.4
-export const PLAYER_FRICTION = 15
-export const PLAYER_SPEED = 55
+export const PLAYER_ACCELERATION = 10
+export const PLAYER_SPEED = 3.8
export const BOOST_FACTOR = 2.5
export const BOOST_DURATION = 0.3
export const BOOST_RESTORE = 0.5
@@ -49,11 +49,9 @@ export function update_movement(p: MovementBase, dt: number) {
else p.stamina += dt / BOOST_RESTORE
p.stamina = Math.max(Math.min(p.stamina, 1), 0)
const speed = PLAYER_SPEED * (p.boosting ? BOOST_FACTOR : 1)
- p.velocity.x += direction.x * dt * speed
- p.velocity.y += direction.y * dt * speed
+ lerp_exp_v2_mut(p.velocity, { x: direction.x * speed, y: direction.y * speed }, dt * PLAYER_ACCELERATION)
p.position.x += p.velocity.x * dt
p.position.y += p.velocity.y * dt
- lerp_exp_v2_mut(p.velocity, { x: 0, y: 0 }, dt * PLAYER_FRICTION)
collide_player(p, dt)
}
function collide_player(p: MovementBase, _dt: number) {