From bcdba7b812884fdbcd735467352baeb608bc9728 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Wed, 2 Jul 2025 15:48:39 +0200 Subject: [PATCH] Fixed Vesna sliding issue --- .../Common/CharacterControls/Player2D.cs | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/scripts/CSharp/Common/CharacterControls/Player2D.cs b/scripts/CSharp/Common/CharacterControls/Player2D.cs index bea8f96..48bba39 100644 --- a/scripts/CSharp/Common/CharacterControls/Player2D.cs +++ b/scripts/CSharp/Common/CharacterControls/Player2D.cs @@ -43,45 +43,55 @@ public partial class Player2D : CharacterBody2D if (!_canHandleInput) return; - - if (Input.IsActionPressed("move_right")) + + bool right = Input.IsActionPressed("move_right"); + bool left = Input.IsActionPressed("move_left"); + bool up = Input.IsActionPressed("move_up"); + bool down = Input.IsActionPressed("move_down"); + bool walkingAnimationPicked = false; + + if (up) { - Velocity = new Vector2(_speed, 0); + Velocity = new Vector2(0, -_speed); MoveAndSlide(); - _sprite.FlipH = false; - _sprite.Animation = "side walking" + _toolString; + _sprite.Animation = "back walking" + _toolString; anyActionPressed = true; - _lastDirection = Vector2.Right; + _lastDirection = Vector2.Up; + walkingAnimationPicked = true; } - if (Input.IsActionPressed("move_left")) + if (down && !walkingAnimationPicked) { - Velocity = new Vector2(-_speed, 0); + Velocity = new Vector2(0, _speed); MoveAndSlide(); - _sprite.FlipH = true; - _sprite.Animation = "side walking" + _toolString; + _sprite.Animation = "front walking" + _toolString; anyActionPressed = true; - _lastDirection = Vector2.Left; + _lastDirection = Vector2.Down; + walkingAnimationPicked = true; } - if (Input.IsActionPressed("move_up")) + if (right && !walkingAnimationPicked) { - Velocity = new Vector2(0, -_speed); + Velocity = new Vector2(_speed, 0); MoveAndSlide(); - _sprite.Animation = "back walking" + _toolString; + _sprite.FlipH = false; + _sprite.Animation = "side walking" + _toolString; anyActionPressed = true; - _lastDirection = Vector2.Up; + _lastDirection = Vector2.Right; + walkingAnimationPicked = true; } - if (Input.IsActionPressed("move_down")) + if (left && !walkingAnimationPicked) { - Velocity = new Vector2(0, _speed); + Velocity = new Vector2(-_speed, 0); MoveAndSlide(); - _sprite.Animation = "front walking" + _toolString; + _sprite.FlipH = true; + _sprite.Animation = "side walking" + _toolString; anyActionPressed = true; - _lastDirection = Vector2.Down; + _lastDirection = Vector2.Left; + walkingAnimationPicked = true; } - + if (Input.IsActionPressed("interact2")) { _sprite.Animation = "back interact";