Can you enlighten me about in what condition the enemy AI decides to first find cover, or should it go after the player?

In an FPS game, I don’t know when the enemy AI should decide to find a cover and when it should go after the player after seeing him. I can make the enemy AI attack, cover, and go after the player, but I don’t know when each one of these should happen. I did try to make it like this: the enemy AI should always first find cover and then attack, but this wasn’t good.
Can you enlighten me about in what condition the enemy AI decides to first find cover, or should it go after the player?

This is a game design question. It’s similar to asking “should the firearms in my game be chrome polished, steel blued, or olive painted?” That’s entirely up to you! Which one is right depends entirely on what kind of gameplay you want to deliver to the player of your game.

So, it sounds like you already have an idea that “always first cover, then attack” isn’t good enough. You used some value function to determine this. Now, it’s your job to pick apart what that value function is, and what would be an improvement according to that function; try that new behavior, and see if it’s good enough. If not, repeat!

Some behaviors I would try, to see whether they worked for me:

  • Always attack first for the first 3 (or first N) enemies, and keep the rest (if there are more) in reserve in cover.
  • Always attack, but if taking damage (or taking damage when less than 50% (or M%) health) then look for cover.
  • Look for cover within 3 meters (or within S meters) and if there, take cover, else attack.
  • For many enemies, look for flanking positions in cover, and implement a slow moving-while-attacking behavior to move to those flanking positions.
  • Randomly pick one, with chance X, Y, and Z% each. Each time the enemy takes any damage, and perhaps every 6 seconds (or T seconds) randomly pick a new thing to do.

Obviously, these will all lead to different gameplay feels, and have different complexity of implementation. You will probably also want to add other behaviors that may interrupt on top, such as “when an ally is down and nearby, run to them and try to administer first aid” or “when an ally is low on ammo, try to move close to them to resupply them” or various kinds of surrounding/pressure/suppression/flanking tactics.

Maybe start with the random, because it’s probably easiest to implement, and go from there?

1 Like

You could go the way of GOAP AI (Goal Oriented Action Planning). The ai would have internal conditions to react to set situations based on weighted biases of specific parameters. There are a couple of examples on github that can give you a broader idea as well a couple of good GDC talks

https://www.youtube.com/results?search_query=gdc+goap

If I were you, I would watch gameplay videos and take note of how AI behaves.

But what it all comes down to is that you’ll likely need to trial and error this.