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,11 +171,16 @@ public class AIEntity : Entity {
float lastDist = float.MaxValue;
Transform chosenEntity = null!;
foreach (Transform other in entityParent) {// Find the closest entity
if (other.GetComponent<Entity>() 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 (lastDist <= entity.AIStats.closeEnough)
break;
}
}
}
}