Artificial inteligence

Today I will speak about AI. More specific about the AI we implemented in our stealth game.
This post will cover every detail of how we planned the AI. Unfortunately we have not implemented all of our ideas in code because it is quite advanced and there is not enough time to create it. But we have the most important ideas.
Our guards will use the AI to chase and kill the player. This is pretty important in this kinds of games because it is the only thing that can kill you, so we have to make them smart but not too strong or weak.
So lets start by defining our AI states.
  1. Idle state
  2. Investigate state
  3. Attack state
  4. Chase state
  5. Request state
I’ll will cover all of these in a order

1. Idle state

The idle state defines a path that is unique for every guard. The idle state is made up of points. Every guard walks from point to point, creating the illusion of a patrolling guard.
If the guard sees the player, the guard will switch to the attack state.
If the guard hears a sound, the guard will switch to the investigate state and find a path to the sound center point.
This image will illustrate how a guard can hear a sound.

2. Investigate state
This state uses a calculated path to walk trough. At the same time as the guard moves, he will look from side to side, creating the illusion that he is investigating.
Also, when the guard enters this state, it will start a timer. When this timer reaches 10 seconds or more, the guard will fallback into idle state.
If he hears anything he will calculate a new path to that sound and so forth. Also, if the guard hears anything, the timer will be restarted.
If the guard sees the player, the guard will switch to the attack state.

3. Attack state
This state is ONLY active when the player is inside the guards vision.
If the guard has a weapon and ammunition, the guard will shoot at the player. But if the guard has not weapon or have no ammunition, the guard will switch to the request state.
If the guard looses focus of the player, the guard will switch to the chase state.

4. Chase state
This state should be entered when the player goes out of the guards vision. The guard will find a path to the point where he lost you(at the guards vision border) and start sprinting towards it. The guard will rotate towards the next point in its calculated path.
If the has no more path to walk, it will go back to the idle state.
If the guard sees the player, it will switch to the attack state.

5. Request state
This state is entered when the guard has no ammunition or no weapon.
The guard will find the a way to the nearest guard and run to him for help. Lets call that guard B
When the guard reaches guard B, guard B will give him a new weapon or more ammunition. Now both the guard will switch state to the chase state and finding a way to the point where the guard last saw the player.


Most of this uses the a pathfinding algorithm which I have covered in another blogpost.
As I said before, we have not implemented this but this was just our vision of the AI.
Instead we only had the Idle, chase and the attack state. Maybe we will add the investigate state later but that is not definite.

// Anthon Fredriksson

About Anthon Fredriksson

2013 Programming