Back in 2011 Dan Vávra wrote a series of five articles about game AI that was published at Games.cz. It focuses mostly on FPS games. The English translation of the first article is brought to you thanks to @bebuce (translation) and @PhanTom_CZ (proofreading).
#Artificial intelligence in games #1: Forget about intelligence
Right at the beginning I have a disclaimer to make; even though I have experience with AI implementation and design, I am not a programmer myself. Moreover, this topic is highly involved and the series of these four articles is therefore no more than a very brief and very general introduction and I am bound to commit many inaccuracies. I want to ask those, who are AI professionals (there is not many of those in Czech Republic and I probably know most of them) to be patient, because the goal is just to familiarize our readers with what AI is and what is it used for in games.
Gaming AI is not an actual intelligence per se. A true intelligence should be able to learn, to react to external input and make autonomous decisions or at least try to. The artificial “intelligence” in games cannot do this and will not be able to for a long time yet. The goal of AI in games is to be an opponent or a partner to the player and to appear as a living being that behaves appropriately in the given situation as much as possible. The number of situations in games is, fortunately for the programmers and designers, very limited and usually consists primarily of fights with the player in a way that seems the most authentic.
Computer-controlled character must therefore be able to navigate around the game environment, attack the player, defend from his attacks, exploit the game environment to its advantage and eventually to cooperate with other computer controlled characters. If we wanted this from a robot moving in the real world, this would be a task worthy of a supercomputer, because just the orientation in such an environment is nothing funny.
Luckily, in the game the designers can give hints and guide the AI in various ways. As a result the AI doesn’t work as an “inteligence”, but technically as a primitive automaton which makes decisions based on simple rules: You see the player? Shoot; Got hit? Say “Auch” and take cover; Run out of ammo? It’s over there, go and get it.
Bulletstorm (2010)
Navigation
The most basic thing we expect from an AI is that it can move. To simply throw it into a 3D level mesh and let it figure it out on its own would require that supercomputer I mentioned and an actual intelligence which can analyze, remember and learn, which is not really possible. Therefore essentially every game contains some form of navigation data which the AI relies on if it needs to move from A to B. Usually it is some form of a navigation mesh or linked checkpoints that tell the ingame character where it can walk.
In the past designers were drawing checkpoints by hand, nowadays they usually get computed automatically. This mesh replaces the need for a memory and ability to recognize the surroundings. The only concern of the NPC is to calculate the shortest path to its destination using these points. The advances of physics inside games brought another problem: what to do when the player blocks the NPC’s path with a movable object? The AI needs to reroute, which is not difficult by itself. The problem appears when the player blocks all the paths and the goal becomes unreachable.
Take an example of a hypothetical situation in an open world game like Fallout. The player is to follow an NPC into a building where a plot twist is about to happen. What happens if the player parked a truck right in front of the building door? Shit happens. Asking the AI to get in and move it somewhere else is a task worthy of an actual intelligence. The designers have to start cheating. They can place some indestructible barriers so that the vehicle cannot get there, but that breaks the impression of an amazing physics, if the rest of the game allows bringing down full grown oaks. They can make the car disappear—but that might make the player mad when he comes back for it later—or teleport it to another place. All these situations demand a large amount of foresight from the designers and considering the number of possible places like this, it’s essentially impossible to prevent all such situations. The bigger the world is and the more possibilities are there, the more complicated it gets.
Fallout 3 (2008)
Another variant is when the AI is following the player. A telling example is the Elder Scrolls series. Veterans may remember the utter desperation in Morrowind, where it often happened that the character which should accompany you simply got lost and the quest where the character was included was then impossible to finish. This could happen for a variety of reasons: in a difficult terrain the player would climb to a place with no navigation mesh and the NPC could not follow, getting stuck somewhere. If the player did not notice, that was the end. Sometimes the player was attacked and decided to flee, but the NPC started fighting and lost the player.
In Fallout 3 the designers decided to simply cheat. If the NPC and the player get separated for whatever reason, the NPC is teleported somewhere out of sight in his vicinity like if nothing happened. It sometimes feels funny when for example you leave a building through the only single exit and the NPC who was 100 meters behind is suddenly waiting for you outside, though it prevents much worse situations form happening.
Both these cases show why Game designers are not eager to make complex missions with too much physics infolved or where the player has to cooperate with a large amount of story driving NPCs. If they really want to have that in the game, they usually solve it by scripting.
Killzone 2 (2009
Smoke and mirrors
With the exception of games based purely on AI (strategy games like Sims and Spore), scripting is a larger part of game design than the AI. The developers have to keep telling the NPCs what they are supposed to be doing in every moment of gameplay. Some essential activities can be coded directly into the AI (NPCs walking around the town in Assassin’s Creed), the more difficult ones and the single-time ones have to be scripted by the designer.
The player is to walk somewhere, the NPC talks to him and then leads him elsewhere? The designer solves this by hardcoding step by step what it should do: when player presses the button, play sentence and animation XY, walk to point A, open the door, walk to point B and play animation YZ. If the player is more than 10 m away, wait for him. If he does not get closer in X seconds, shout on him to move his butt.
To ensure this will not get screwed, the designer must clear the path for the AI, remove obstacles and enemies and stop the player from messing something, or at least make sure the NPC will not die, say by making it immortal. These are the situations in Crysis 2 or Bulletstorm when you are allowed to walk, but only slow and you cannot shoot, so you cannot get in a way or take out somebody important.
The most pronounced example in Crysis 2 is when you walk with Gould to the Cell laboratory to sit in the diagnostic chair and at the moment when Gould gets through the glass door, it smashes close right in front of your face so you cannot get in and shoot the staff inside before Gould talks to them.
Crysis 2 (2011)
The puppet show style design goes to the extreme in current FPS games where the script plays the main part and the AI plays the second fiddle. The player moves through a corridor and the behaviour of everything around is strictly predetermined. The puppet show only stops for a moment when the player falls behind. Whenever the player gets to a predetermined spot, it triggers a new series of animations. The only interactive element driven by an AI is that the player needs to shoot a few of the puppets before they shoot him or succeed in acting out a game over script (like setting off a bomb)
The AI is restricted to the bare minimum in these cases, the enemies are simply waiting for the trigger and the moment when it goes off they jump out and start shooting. In the better case they can move around in some restricted space and take cover. The situation is usually set up so that the player can’t do anything to spoil the show: to retreat or to run through the enemy lines without killing them. The show requires that player must kill everyone before the next act begins.
An honorable exception is the Modern Warfare 2, where Infinity Ward dared to occasionally allow players to venture into more open nonlinear areas and then let the artificial intelligence to move around rather freely and naturally during the firefight. Only when the player cleared the arena, the puppet show script went running again.
Modern Warfare 2 (2009)
You got a lot of material to think about AI in current games for today. Next week in the second part we will explore the senses our AIs have and how are they used in combat and spatial navigation, and the idiocies that NPCs sometimes commit.