Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scenes/game_logic/walk_behaviors/input_walk_behavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var input_vector: Vector2
var is_running: bool:
set = _set_is_running

var _is_stuck: bool
var _last_safe_position: Vector2


func _set_is_running(new_is_running: bool) -> void:
if is_running == new_is_running:
Expand Down Expand Up @@ -53,6 +56,15 @@ func _physics_process(delta: float) -> void:
character.velocity = character.velocity.move_toward(input_vector, step * delta)
character.move_and_slide()

# Check if the player got stuck (is colliding after the move_and_slide).
var collision := character.move_and_collide(Vector2.ZERO, true)
_is_stuck = collision != null
if _is_stuck:
character.velocity = Vector2.ZERO
character.position = _last_safe_position
else:
_last_safe_position = character.global_position

# When using an analogue joystick, this can be false even if the player is
# holding the "run" button, because the joystick may be inclined only slightly.
is_running = input_vector.length_squared() > (speeds.walk_speed * speeds.walk_speed) + 1.0