FSM Player input

This commit is contained in:
MaddoScientisto 2025-02-28 22:49:55 +01:00
commit cc0d698bb5
7 changed files with 180 additions and 106 deletions

View file

@ -0,0 +1,48 @@
using Godot;
public partial class PlayerAnimationProvider : Node2D
{
[Export]
public AnimatedSprite2D _animatedSprite {get; private set;}
[ExportCategory("Animation Names")]
[Export]
public string WalkRightAnimationName {get; private set;} = "walk_right";
[Export]
public string WalkLeftAnimationName {get; private set;} = "walk_left";
[Export]
public string WalkDownAnimationName {get; private set;} = "walk_down";
[Export]
public string WalkUpAnimationName {get; private set;} = "walk_up";
public void SetAnimation(Vector2 velocity)
{
if (velocity.X == 0 && velocity.Y == 0)
{
_animatedSprite.SpeedScale = 0;
}
else
{
_animatedSprite.SpeedScale = 1;
}
if (velocity.X > 0)
{
_animatedSprite.Play(WalkRightAnimationName);
}
else if (velocity.X < 0)
{
_animatedSprite.Play(WalkLeftAnimationName);
}
else if (velocity.Y > 0)
{
_animatedSprite.Play(WalkDownAnimationName);
}
else if (velocity.Y < 0)
{
_animatedSprite.Play(WalkUpAnimationName);
}
}
}