Add elements
Attempt to block line of sight with walls
This commit is contained in:
@@ -39,7 +39,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
[Dependency] IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
[Export]
|
||||
public EnemyStatInfo EnemyStatInfo { get; set; } = new();
|
||||
public EnemyStatInfo EnemyStatInfo { get; set; } = default!;
|
||||
|
||||
public static PackedScene CollisionDetectorScene => GD.Load<PackedScene>("res://src/enemy/CollisionDetector.tscn");
|
||||
|
||||
@@ -57,6 +57,8 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
[Node] public AnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||
|
||||
[Node] public RayCast3D Raycast { get; set; } = default!;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
EnemyLogic = new EnemyLogic();
|
||||
@@ -99,7 +101,22 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
private void LineOfSight_BodyEntered(Node3D body)
|
||||
{
|
||||
EnemyLogic.Input(new EnemyLogic.Input.Alerted());
|
||||
var overlappingBodies = LineOfSight.GetOverlappingBodies();
|
||||
foreach (var overlap in overlappingBodies)
|
||||
{
|
||||
Raycast.LookAt(GameRepo.PlayerGlobalPosition.Value, Vector3.Up);
|
||||
Raycast.ForceRaycastUpdate();
|
||||
if (Raycast.IsColliding())
|
||||
{
|
||||
var collider = Raycast.GetCollider();
|
||||
if (collider is IPlayer player)
|
||||
{
|
||||
Raycast.DebugShapeCustomColor = Color.FromString("Purple", Colors.Purple);
|
||||
EnemyLogic.Input(new EnemyLogic.Input.Alerted());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
|
||||
Reference in New Issue
Block a user