From f8c78deed463948c2120a42c3a14423a9428fc1c Mon Sep 17 00:00:00 2001 From: 3002102 <3002102@stud.hs-mannheim.de> Date: Sun, 12 Apr 2026 15:22:32 +0200 Subject: [PATCH] fixed animation bug in sprite on diagonal walking --- scripts/player.gd | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/scripts/player.gd b/scripts/player.gd index fe4a1af..5597bcc 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -7,19 +7,18 @@ func _physics_process(delta): var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") velocity = direction * speed - if direction.x < 0: - animated_sprite_2d.play("walk_left") - if direction.x > 0: - animated_sprite_2d.play("walk_right") - if direction.y < 0: - animated_sprite_2d.play("walk_up") - if direction.y > 0: - animated_sprite_2d.play("walk_down") - - - - if direction.x == 0 and direction.y == 0: + if direction == Vector2.ZERO: animated_sprite_2d.play("idle") + elif abs(direction.x) >= abs(direction.y): + if direction.x < 0: + animated_sprite_2d.play("walk_left") + else: + animated_sprite_2d.play("walk_right") + else: + if direction.y < 0: + animated_sprite_2d.play("walk_up") + else: + animated_sprite_2d.play("walk_down") move_and_slide()