Turret animation controller

This commit is contained in:
MaddoScientisto 2025-05-24 22:45:17 +02:00
commit 63aeb0a6e9
2 changed files with 117 additions and 0 deletions

View file

@ -73,6 +73,19 @@ public partial class PlayerAnimationProvider : Node2D
}
}
public void SweepSprite(float angle, float sweepAngle)
{
if (_animatedSprite == null) return;
var frames = _animatedSprite.SpriteFrames.GetFrameCount("default");
// Map angle (-SweepAngle/2 to +SweepAngle/2) to frame (0 to 5)
float normalizedAngle = (angle + (sweepAngle / 2)) / sweepAngle;
int frame = Mathf.Clamp((int)(normalizedAngle * frames), 0, frames);
_animatedSprite.Frame = frame;
}
public void SetAnimation(Vector2 direction)
{