From 4bafa41c9de4859b9adb10165a72dab8d83f491c Mon Sep 17 00:00:00 2001 From: Ivan Kuzmenko <6745157+rndtrash@users.noreply.github.com> Date: Wed, 16 Aug 2023 22:11:50 +0300 Subject: [PATCH] Player animations --- scripts/Player.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/Player.cs b/scripts/Player.cs index d6eb815..908505d 100644 --- a/scripts/Player.cs +++ b/scripts/Player.cs @@ -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;