When we consider artificial intelligence for non-player characters (NPCs) in games and how it evolved over the years, two of the most influential games come from the first-person shooter genre: Half-Life and Halo 2.
Welcome to Black Mesa
Half-Life, released on PC by Valve back in 1998 and it was a real turning point for characters in action games. They had their own behaviours, would react to the world around them, and could help tell the story of what was happening in the game world. There were other games that had done this around the same time, notably Goldeneye 007 on the Nintendo 64, but Half-Life set a standard that every game after it tried to emulate.
Half-Life uses a really simple approach to AI called finite-state machines. You design a character’s behaviour to be in a state, such as patrolling an area of the map or attacking the player and then create events that say why they would transition from one state to another. A soldier might continue to patrol the map, moving between waypoints as they move around until they see the player, after which they would start shooting. However, they might then retreat if the player gets too close or they take too much damage.
While it’s fundamentally a rather simple approach, it can still prove quite powerful, provided you think through the design. You can design numerous individual, unique behaviours you want your characters to have and then the reasons for why they move between them. But it can get a little too complicated after a while, as sometimes transitioning from one side of the state machine to another might become incredibly complicated. Or a character inadvertently transitions into behaviours you don’t want them to.
One evolution of this was to create hierarchical finite state machines, which are, in essence, state machines inside state machines. So you might have one state machine for patrolling and investigation behaviours, but then if you go into combat, it moves to a different state machine in the same system. You can make it much more layered and structured to suit your needs. Even though this is – comparatively – old and a simple approach to designing characters, it’s still used by some of the biggest games today. The Last of Us series and even the more recent DOOM games use hierarchical finite state machines to this day.
I Need a Weapon…
While Half-Life set one standard for developers to follow, Bungie released Halo 2 in 2004 and set another one with what we now call behaviour trees. In a behaviour tree, all of the different behaviours are contained within a large tree structure, and as you move down from the root to the behaviours on the edges, you define rules that dictate which branches will be active based on what’s happening in the world as you play. It can then do individual actions or string them together in sequences of intelligent behaviour.
This is so useful because in games like Halo you can quickly discover different situations. Like having a whole subtree just for what to do if the player is in a vehicle. Or if none of the enemies have seen the player yet, what should we do instead? Plus, you can reset it very quickly if something changes. It’s why the grunts panic when you kill an elite enemy in front of them because killing the high-ranking officer nearby tells all NPCs in proximity to reset their behaviour tree, as it has unlocked a new behaviour for them to perform.
While it sounds really simple, in practice, it can create large spanning trees designed to work in a variety of different situations. It might get a little hard to look at, but they’re still easy to follow with a bit of effort.
Behaviour trees are pretty much the standard for AI in games today. They’re available to use as part of the Unreal Engine, and a lot of AAA studios build their own implementations. A big reason for this is they’re really accessible to designers. And that’s really important for any AI tool for games. You want to enable designers to make the best games they can. By giving them useful and accessible tools to create new experiences, you’re going to help make that a reality.
Halo and Half-Life are two of the most influential first-person shooters in history, and as we’ve seen here, they had a bit of impact on game AI as well. Of course, these aren’t the only games that have influenced the field. Be sure to check back for more of the History of AI series as we look at shooters such as Left 4 Dead and F.E.A.R., and many other games and genres too!
If you’re keen to learn more about the design and development of the AI of Half-Life, check out the episode dedicated to finite state machines on the AI and Games YouTube channel.