Face player towards aim direction

This commit is contained in:
Marco 2025-04-08 10:44:06 +02:00
commit 25a9bc1d78
9 changed files with 75 additions and 58 deletions

View file

@ -53,42 +53,56 @@ public partial class PlayerAnimationProvider : Node2D
{
_animatedSprite.Hide();
}
public void SetAnimation(Vector2 velocity)
{
if (velocity.Length() == 0)
{
_animatedSprite.SpeedScale = 0;
}
else
{
if (velocity.Length() > 40)
{
_animatedSprite.SpeedScale = 1;
}
else
{
_animatedSprite.SpeedScale = 0.8f;
}
}
if (velocity.X > 0)
public void SetAnimationSpeed(Vector2 velocity)
{
if (velocity.Length() == 0)
{
_animatedSprite.SpeedScale = 0;
}
else
{
if (velocity.Length() > 40)
{
_animatedSprite.SpeedScale = 1;
}
else
{
_animatedSprite.SpeedScale = 0.8f;
}
}
}
public void SetAnimation(Vector2 direction)
{
if (direction == Vector2.Zero)
return;
float angle = Mathf.RadToDeg(direction.Angle());
// Normalize to 0-360
if (angle < 0)
angle += 360;
string animToPlay;
switch (angle)
{
_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);
case >= 45 and < 135:
_animatedSprite.Play(WalkDownAnimationName);
break;
case >= 135 and < 225:
_animatedSprite.Play(WalkLeftAnimationName);
break;
case >= 225 and < 315:
_animatedSprite.Play(WalkUpAnimationName);
break;
default:
_animatedSprite.Play(WalkRightAnimationName);
break;
}
}
public void Blink()