I am developing a stealth game. In the game when enemy sees player he starts chasing it. But there are a lot of covers. If player just goes behind of a wall it will be out of sight for this enemy. But I want my enemies little bit more realistic.

So i did do some further implementations... For example if player goes out of sight enemy remembers last seen position and goes there anyway.

Than i save the move direction of player on the position where he was last seen. So when enemy goes there he looks this direction which he may probably catch a glimps of the player and start chasing again.

But if player is still no where to be seen I want my enemy to look around little bit, search for the player maybe. I couldnt come up with an algorithm to do that.

Also if on the last seen position and last move direction there is another wall, enemy goes this position and looks stupidly to the wall which also dont seem realistic at all...

Does anybody have any suggestions?


2 Answers 2


A system similar to this is used in the Splinter Cell games.

Once the AI have validated that Sam is no longer at his last known position, they begin systematically scouring the available cover/corner locations, treating them like a checklist.

At the start of the search, they check off every cover position they already have line of sight to, then move to flank/scan remaining cover points. Once an AI has scanned a cover location, it checks it off. Once they've exhausted their search possibilities, they fall back on more general patrol behaviours.

This could help with your "turn into the wall" case. If the wall has an alcove that could serve as cover, then it's a sensible site to check and they'll turn to scan it. If it's a completely blank wall, it won't be tagged as a cover location and they'll ignore it and look at the next closest cover in that general direction.

  • \$\begingroup\$ Thanks for the suggestion. I will try to implement something smilar and check out if it works. Difficulty is that my game is a top-down stealth game. There is no cover like in splinter cell. There are a lot of walls or bushes or cars which player can hide behind. Do you suggest that I mark every wall or so as cover, get all the covers in a radius and make enemy walk around all the covers and see if player hide there? \$\endgroup\$
    – laymelek
    Mar 6, 2018 at 10:03
  • \$\begingroup\$ So you're saying there are places where the player can stand to be shielded from line of sight from opponents. That sounds an awful lot like a cover position. ;) \$\endgroup\$
    – DMGregory
    Mar 6, 2018 at 11:32
  • \$\begingroup\$ Haha :) you are right... I meant there is no cover in the sense of "marked covers" If I say here is a wall, it is a cover check here the enemey is going to run around the whole wall or walls... Althoug it may not be the worst thing. \$\endgroup\$
    – laymelek
    Mar 7, 2018 at 7:29

Given how your question is presented, I'd say the real answer is to take a step back and think how you want your AI to behave, since how your AI behaves must fit the kind of game you are making:

  • A tactic/puzzle-like game like the first Commandos game, your current behavior would be enough if you add a little "look around" animation
  • A purely stealth game would use an AI like the described by @DMGregory in Splinter Cell
  • An stealth/action game would work with the guard going into a "search and destroy" mode, where he will move randomly around the area until you are seen again, or even make him know your current position for X seconds, so you have to stay away from his line of sight for an amount of time.
  • A more systemic game with emergent gameplay, you should not only think about the guard's AI, but the AI of all agents and how they interact with each other.

There is no way to improve an AI in the vacuum (besides performance), since you first need to have a clear picture of what you want to achieve with your AI in order to be able to measure the quality of it's behavior.

Of course, once you have a clear idea, you will be presented with a lot of questions about how to achieve that goal.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .