Player animations

This commit is contained in:
Иван Кузьменко 2023-08-16 22:11:50 +03:00
parent e9df7ae609
commit 4bafa41c9d

View file

@ -24,11 +24,24 @@ public partial class Player : CharacterBody2D
{
velocity.X = direction.X * Speed;
velocity.Y = direction.Y * Speed;
var animationName = "sideways";
if (velocity.Y > 0.001f)
animationName = "down";
else if (velocity.Y < 0.001f)
animationName = "up";
if (velocity.X != 0)
animationName = "sideways";
Sprite.FlipH = velocity.X < 0.001f && animationName == "sideways";
Sprite.Play(animationName);
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Speed);
Sprite.Stop();
}
Velocity = velocity;