You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/CharacterControls/RaycastDetector.cs

41 lines
1014 B

using Godot;
namespace Babushka.scripts.CSharp.Common.CharacterControls;
public partial class RaycastDetector : RayCast2D
{
[Export] private bool _active = true;
private DetectableInteractionArea? _lastDetected;
public bool IsActive
{
get => _active;
set
{
Visible = value;
_active = value;
}
}
public override void _PhysicsProcess(double delta)
{
if (!_active)
return;
if (IsColliding())
{
if (GetCollider() is DetectableInteractionArea interactionArea)
{
if (_lastDetected != null && _lastDetected != interactionArea)
{
_lastDetected.NoLongerDetected();
}
GD.Print("Colliding with: " + interactionArea.GetParent().Name);
_lastDetected = interactionArea;
interactionArea.Detected();
}
}
}
}