I'm working on enemy AI and have run into the following issue. In the examples below, I have three enemy AI units moving through three different waypoints in a never ending cycle. I have them set up to stay in formation a relative distance from each other.
This works just great until I add another condition. I have it set up where if the player moves into any of the enemy unit's detection range, the enemy stops their patrol to chase and shoot at the player until the players leaves their detection range. However, two weird bugs popped up that I need help with cause I'm out of ideas at this point.
Patrol AI - 3 enemies fire
1) In the above file, the bug that comes up is that I can move the player unit with the arrow keys within range of the enemy and then run out of their range. All three enemies chase and shoot as long as I'm in their range. If I leave their range, they try to go back to their patrol. Situations come up though where I can lead one enemy away while the other two continue on the patrol. Eventually, this messes things up and freezes the enemies. I would like every enemy in the patrol to chase regardless of if they were not the enemy unit that detected my player..
Patrol AI - attempted Pick All fix
2) This is my attempt to fix problem number one. I thought if I used a Pick All statement to make all enemies "active in the loop" again, that I could then run another sub FOR statement to tell all enemies in the array to attack together at once to prevent the problem above. It's important that the array is told to attack because I plan on having other enemies in different arrays of the same object type and I don't want them all attacking - just those enemies in the array where the player was detected. Anyway, this method didn't work as you can see. It changes it so that only one enemy unit attacks and it still messes up the relative formation.
Sorry for the length of this post but any assistance would be greatly appreciated as I'm banging my head on the wall on this one so far.