Check IsTargetable in FindTarget

This commit is contained in:
Jason Durand 01 2022-04-03 15:19:35 -04:00
parent 4b96196b69
commit 417bcd9485

View File

@ -171,12 +171,17 @@ public class AIEntity : Entity {
float lastDist = float.MaxValue; float lastDist = float.MaxValue;
Transform chosenEntity = null!; Transform chosenEntity = null!;
foreach (Transform other in entityParent) {// Find the closest entity foreach (Transform other in entityParent) {// Find the closest entity
float distance = Vector2.Distance(other.position, entity.transform.position); if (other.GetComponent<Entity>() is {} otherEntity) {
if (distance < lastDist) { if (entity.IsTargetable(otherEntity)) {
lastDist = distance; float distance = Vector2.Distance(other.position, entity.transform.position);
chosenEntity = other; if (distance < lastDist) {
if (lastDist <= entity.AIStats.closeEnough) break; lastDist = distance;
} chosenEntity = other;
if (lastDist <= entity.AIStats.closeEnough)
break;
}
}
}
} }
if (chosenEntity != null) { if (chosenEntity != null) {