From 417bcd9485b042f8a1f93ce67606737758fc1e47 Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 15:19:35 -0400 Subject: [PATCH] Check IsTargetable in FindTarget --- Assets/Scripts/AIEntity.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/AIEntity.cs b/Assets/Scripts/AIEntity.cs index 686e4f8..4c267b0 100644 --- a/Assets/Scripts/AIEntity.cs +++ b/Assets/Scripts/AIEntity.cs @@ -171,12 +171,17 @@ public class AIEntity : Entity { float lastDist = float.MaxValue; Transform chosenEntity = null!; foreach (Transform other in entityParent) {// Find the closest entity - float distance = Vector2.Distance(other.position, entity.transform.position); - if (distance < lastDist) { - lastDist = distance; - chosenEntity = other; - if (lastDist <= entity.AIStats.closeEnough) break; - } + if (other.GetComponent() is {} otherEntity) { + if (entity.IsTargetable(otherEntity)) { + float distance = Vector2.Distance(other.position, entity.transform.position); + if (distance < lastDist) { + lastDist = distance; + chosenEntity = other; + if (lastDist <= entity.AIStats.closeEnough) + break; + } + } + } } if (chosenEntity != null) {