AI (Artificial Intelligence) is used in almost every game to give non player characters or objects the illusion of intelligence. There are multiple types of AI, spanning from combat AI, to movement AI, to puzzle solving AI. The artificial intelligence in most modern games focuses on the ability to move characters, the ability to make decisions on where and how to move, and the ability to think tactically or strategically.
Movement
One of the most important aspects for artificial intelligence in most games is the ability for the AI system to be able to move NPC's. The movement algorithms for the AI system need to interact with the strategy system and the decision system. The strategy system tells the AI how to react to a certain scenario, and what its possible options are in terms of actions such as movement. The decision making system for the AI, then decides how it will choose from these possible options. In terms of movement, the AI will often choose the shortest path to its goal. A very common path finding technique for AI is with the use of a navigation mesh.
A navigation mesh is a low poly mesh that is placed over top of the regular world mesh, and used for collision and to define paths. The reason that a navmesh is used separately from the regular mesh in this case, is to reduce computations. There are two ways to sample from a navmesh. One is to define paths along the edges of the polygons, and another is to define nodes on the vertices of the polygons for the character to interpolate between.
There are multiple types of movement behavior for AI. The most popular being seek, flee, and patrol behavior.
A seek algorithm will take the position vector of the NPC, relative to the position vector of its target, and move the character or object toward its target. To do this, a path is defined by the AI system and then a position, direction, and velocity are requested by the algorithm. The defined path may change as the target for the character changes. A more advanced version of seek behavior that is often seen in games is pursue behavior. Pursue behavior attempts to predict where the player will be next, and attempts to cut them off. The opposite of this type of behavior being evade.
Flee behavior can be seen as the opposite as seek behavior. The intent of a flee algorithm is to move a character away from its target (run away from the player). It operates almost exactly the same as seek behavior, but with a negative velocity.
Patrol, or wandering behavior, is mostly to give a character life, and increase the dynamics of a level. It moves the character in the direction of their current orientation, but sets a small random offset for orientation and updates. This makes the character seem like they are aimlessly wandering around. Some games use predefined paths for patrol behavior. This is especially common in games where you are trying to avoid being spotted by NPC's. Generally, the velocity is set lower while in a patrol or wandering state, and then increased when the character is in seek or flee behavior.
To add some realism to the AI system, arriving behavior and steering behavior are often added.
Arriving behavior handles the event of the character arriving its goal. Often, the character will overshoot its target and have to backtrack, this can cause problems such as constant wiggling of the character. The solution to this is to continuously compare the distance of the character to that of its target. If the character is within a certain radius of the target, decrease velocity.
Steering behavior is used to add realism to the turning of the character. In many cases, it is undesirable to have the character constantly facing its target, especially if the target moves. Steering the character turns him smoothly, rather than just snapping his orientation to a certain vector. This is often accomplished by changing the acceleration vector of the character as he is turning.
Decision making and strategy
There are a ton of different algorithms for decision making and strategy for artificial intelligence. They differ from game to game, so there is no definite way to say how its done. However, there are some similarities between games in the decision making and strategy portion of AI.
Decision making is the core portion of AI, as it tells the AI what to do and when/ how to do it. Part of a good decision making system is defining different AI states. Popular states for AI include: idle, aware, intrigued, alert, aggressive, fleeing, and dead.
The idle state often calls upon the patrol behavior for the AI. The character will be set to play predefined idle animations or walk around, not making any decisions on how to react next.
An aware state means that the character will actively be searching for targets. It is like idle, but there are constant calculations for sight, and position relative to a target.
A character will move from the aware state to an intrigued state if it notices something is out of place. The AI will tell the character to abandon its current behavior and seek toward the point of interest.
If the target of the character is spotted, or another defined trigger is activated, the AI will switch from the intrigued state to an alert state. Now the AI is aware of a certain presence or happening, and will begin to carry out its behavior, such as seeking the player.
Once the AI is within a certain threshold of its goal (it has seeked the player), it will switch to an aggressive state. The AI will recognize that it is close enough to engage in combat with the player, and begin executing combat algorithms accordingly.
During flee behavior, the AI will recognize that it needs to exit combat or escape the target or player, and begin to use its flee or escape algorithm.
Dead behavior is similar to that of idle, but the NPC object may execute specific animations, or be deleted/ respawned upon its death.
More about AI will be discussed in further blogs.
References: http://software.intel.com/en-us/articles/designing-artificial-intelligence-for-games-part-1 , Dr. Andrew Hogue INFR3110 lecture slides