Skip to content

Commit

Permalink
Only set movement_action if position is different than current position
Browse files Browse the repository at this point in the history
  • Loading branch information
grepsedawk committed Jun 22, 2023
1 parent 4e64eb3 commit 88938d9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/rosegold/control/physics.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 88938d9

Please sign in to comment.