Enemy AI: Best way for decision handling?
I've done a lot with AI pathfinding, and I'm starting a new "tower defense" based game, where enemies have a designated target and try to get to that, and in the end, defeat that target (which is a "core").
I don't want to simply have enemies go straight to the core like morons, apply damage and hope not to die, I want to have enemies who will target the "core", but also be able to stop and shoot or attack players of the game, defending the "core". Now, what would be the best way to determine this "decision", to stop and shoot at players, or to go to the "core", or to change a different path, possibly throw grenades, what kind of process can I go through? Preferably, do you know of any links to articles where people have already discussed this? I'm not sure what to look up, but I have tried.
Thank you.
Well, a way I would do it is every enemy has either an OverlapSphere or an OverlapCircle being run on it every .1 seconds or something. You can have your pathfinding enabled, then when it detects something within a certain radius, shoot at it, then continue pathfinding to the core.
Answer by jmonasterio · Dec 31, 2015 at 09:38 PM
You can get AI behavior that appears "complex" to the player by implementing a few "simple rules".
The idea is similar to how a flock of birds (or school of fish) appear to fly (or swim) in a very coordinated fashion. The birds aren't all talking to each other :) Instead each bird follows a few simple rules like: "Try to stay the same distance from other birds near me". And "Try to follow the bird in front of me". But to an observer, it looks like the flock is moving in unison.
Anyway, you might want to have a few different rules like:
"If there is a strong unit near me, try to go avoid it".
"If there is a weak unit near me, try to fight it".
"If I am weak, try togo directly to goal as fast as possible".
"If there are already other of my units attacking a unit, ignore the enemy".
"If I see any unit near me, pause to fight it 50% of the time."
Give up fighting if I lose more than 30% of my strength, and continue to goal.
... make up a few more rules of your own.
Each rule should be individually easy to program. That is a benefit of this approach.
Perhaps then, you might have some units that randomly pick from available behaviors. Or some units that only do #1 and #3. Etc.
To the player the behavior may look quite complex even though the rules are simple.
Tune rules as necessary.