From 88938d98ca4dc3522d1c1c9e42e906c13f73274e Mon Sep 17 00:00:00 2001 From: Alex Piechowski Date: Wed, 21 Jun 2023 20:12:17 -0600 Subject: [PATCH] Only set movement_action if position is different than current position --- src/rosegold/control/physics.cr | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rosegold/control/physics.cr b/src/rosegold/control/physics.cr index 4d744221..2e1a41b5 100644 --- a/src/rosegold/control/physics.cr +++ b/src/rosegold/control/physics.cr @@ -74,6 +74,12 @@ class Rosegold::Physics # If there is already a movement target, it is cancelled, and replaced with this new target. # Set `target=nil` to stop moving and cancel any current movement. def move(target : Vec3d?) + if very_close_to? target + @movement_action.try &.fail "Replaced by movement to #{target}" + @movement_action = nil + return + end + if target == nil action_mutex.synchronize do @movement_action.try &.fail "Movement stopped" @@ -176,9 +182,7 @@ class Rosegold::Physics look_action.try &.succeed @movement_action.try do |movement_action| - # movement_action.target only influences x,z; rely on stepping/falling to change y - target_diff = (movement_action.target - player.feet).with_y(0) - if target_diff.length < VERY_CLOSE + if very_close_to? movement_action.target movement_action.succeed @movement_action = nil end @@ -188,6 +192,10 @@ class Rosegold::Physics client.emit_event Event::PhysicsTick.new movement end + def very_close_to?(target : Vec3d) + (target - player.feet).with_y(0).length < VERY_CLOSE + end + class MovementStuck < Exception; end private def send_movement_packet(feet : Vec3d, look : Look, on_ground : Bool)