Player animations
This commit is contained in:
parent
e9df7ae609
commit
4bafa41c9d
1 changed files with 13 additions and 0 deletions
|
@ -24,11 +24,24 @@ public partial class Player : CharacterBody2D
|
||||||
{
|
{
|
||||||
velocity.X = direction.X * Speed;
|
velocity.X = direction.X * Speed;
|
||||||
velocity.Y = direction.Y * 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
|
else
|
||||||
{
|
{
|
||||||
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
|
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
|
||||||
velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Speed);
|
velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Speed);
|
||||||
|
Sprite.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
Velocity = velocity;
|
Velocity = velocity;
|
||||||
|
|
Loading…
Add table
Reference in a new issue