mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 07:45:55 +00:00
Camera sprite sweep
This commit is contained in:
parent
290acba7be
commit
88fd702cea
5 changed files with 59 additions and 7 deletions
|
|
@ -10,15 +10,20 @@ public partial class CameraPlayerDetection : PlayerDetection
|
|||
[Export] public float SweepAngle = 90f; // In degrees
|
||||
[Export] public float SweepSpeed = 1f; // Speed of sweeping
|
||||
[Export] public bool Debug = false; // Enable debug lines
|
||||
[Export] public NodePath SpritePath;
|
||||
|
||||
private float _currentAngle;
|
||||
private float _sweepDirection = 1f;
|
||||
private float _raycastLength;
|
||||
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
_animatedSprite = GetNode<AnimatedSprite2D>(SpritePath);
|
||||
|
||||
var collisionShape = GetNode<CollisionShape2D>("CollisionShape2D");
|
||||
if (collisionShape.Shape is CircleShape2D circle)
|
||||
{
|
||||
|
|
@ -30,6 +35,8 @@ public partial class CameraPlayerDetection : PlayerDetection
|
|||
{
|
||||
base._PhysicsProcess(delta);
|
||||
SweepCamera((float)delta);
|
||||
|
||||
UpdateSpriteDirection();
|
||||
}
|
||||
|
||||
private void SweepCamera(float delta)
|
||||
|
|
@ -58,6 +65,19 @@ public partial class CameraPlayerDetection : PlayerDetection
|
|||
_debugLineEndPoint = endPoint;
|
||||
}
|
||||
|
||||
private void UpdateSpriteDirection()
|
||||
{
|
||||
if (_animatedSprite == null) return;
|
||||
|
||||
var frames = _animatedSprite.SpriteFrames.GetFrameCount("default");
|
||||
|
||||
// Map angle (-SweepAngle/2 to +SweepAngle/2) to frame (0 to 5)
|
||||
float normalizedAngle = (_currentAngle + (SweepAngle / 2)) / SweepAngle;
|
||||
int frame = Mathf.Clamp((int)(normalizedAngle * frames), 0, frames);
|
||||
|
||||
_animatedSprite.Frame = frame;
|
||||
}
|
||||
|
||||
private Vector2 _debugLineEndPoint;
|
||||
|
||||
public override void _Draw()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue