Building believable AI in games: Halo

Building believable AI in games: Halo

James chats with developer Damian Isla about his AI work in Bungie’s venerable first-person space shooter franchise.

When you think about artificial intelligence in videogames, you might immediately think of one of the millions of creatures designed to jump out of a corridor and wail aimlessly at the player who’s lying in wait to mow them down with a sawn-off shotgun. But there’s a lot more to it than that. Maybe for some it’s enough that an enemy comes at you the moment it spots you, giving no thought to its own safety or well being. But what if that enemy could hear you coming, then sneak around to your position? What if they could radio their squad and have them take up defensive positions in ready for your approach? And what if none of that was pre-scripted, but it happened ‘naturally’ because the AI decided that was the best course of action?

A good AI should help immerse you in the game world they are in, and to get them there takes both a lot of time and developer brainpower. In order to understand more about the process of creating an immersive AI for a game, I got in touch with some people who know better than most the time and effort it takes to get it right.

In this first of three email discussions with AI programmers and game developers, I ask Damian Isla, co-found of The Molasses Flood--who recently released The Flame and the Flood--about his prior work on designing and building the AI in the crescendo of Bungie’s epic Halo series, specifically Halo 2 and Halo 3.

HYPER: One of the things I remember vividly about both Halo 2 & 3 was the interaction between the Elites and the Grunts, which showed off the very clear hierarchy that was in place within The Covenant between the different races. How much of a challenge was it to portray this through their behaviour?

DAMIAN: The most memorable of the interactions between elite and grunt - that the grunts would turn tail and run when an elite was killed in their vicinity - was actually part of Halo 1. In Halo 2 (and even more in Halo 3) we expanded and deepened those interactions.

One thing that is quite hard to do in game AI is subtlety - there's just so much going on, subtlety flies straight over the player's head. So if you want to portray something like a social hierarchy in the midst of a gun-battle, you really have to crank it to 11. That's why the grunts fleeing when the elite dies works well. The fleeing animation is way over-the-top, and accompanied by loud squealing-grunt sounds. That's why it was something that actually read for players.

There were other elements that reinforced the hierarchy - grunts always positioning themselves in front of the elites, various vocal cues, etc. - but nothing ever quite reached the crisp clarity of that fleeing mechanic.

Halo 2 saw the addition of the Brutes as a major threat; how did you go about giving them a different AI personality than the Elites and other established enemy characters?

The brutes didn't have that big a role in Halo 2 - in only a couple levels are they the main threat. The chief concept behind them at the beginning was that they were a more feral, emotional enemy than the elites, who we thought of as more crafty and strategic. So the big difference ended up being that whereas the elites hide when you took down their shields, the brutes, when their health dropped below a threshold, would suddenly go into "berserk" mode and charge straight at you. That change was intended to alter the calculus that went into a player's decision on whether to attack/engage or not. "I have to be ready with my killing blow before I start to whittle this guy down", that kind of thing.

Despite that approach, the Brute combat model in Halo 2 did not reach, I would say, the depth of the elite-grunt combo, and that was okay, since again the Brutes were not really that widely used as an enemy in Halo 2. For Halo 3, we knew the Brutes were going to be the primary enemy pretty much throughout, so we went back to the drawing board with various plans to deepen the combat experience. That happened in two ways.

First, the brutes got shields! Just like elites, killing them became kind of a two-stage process (first chew away shields, then headshot, or melee, or otherwise finish them off in a more surgical manner). Adding that little bit of complexity, we found, made a battle more interesting and more strategic (especially when the player could SEE, through visual feedback, how much of a Brute's shield was left, and could use that information in deciding who to attack when).

Second, we started to organise brute encounters around the concept of "the pack", and we started to think about how the brutes would fight when there's a chieftain around, vs. when there's not, how they would position themselves relative to one another, and how they would work together. Basically whereas in Halo 2 the player was fighting a bunch of individuals who happened to be standing near each other, in Halo 3 we strove to make the brutes feel like a pack that worked together. Their overall character remained the same - a feral, emotional beast of an enemy - but the execution, I think, improved vastly, to the point where the brutes make up some of my very favourite encounters, particularly those in contained locations.

So to go back to the original question: how did we go about giving them different personalities? Really again it’s about taking a concept - say the concept of a pack - and trying to go as far as we possibly can with it, and expressing it in as many ways as possible. No subtlety. The concept of the pack worked its way into their basic attack/hide/flee behavior, their combat positioning, the structure of the encounters, the combat dialog, everything.

Was it a big technical challenge to create such an advanced AI (for the time) on a system like the Xbox 360? Did you have to make any concessions to your original plans to accommodate the tech?

There were definitely many concessions made, though not as much as you would think in the realm of pure "decision-making," which is usually what people think of when they think of AI (i.e. how does the character decide to do what they're going to do at every second?).

Even today, there are really two primary "expensive" processes (i.e. they take up a bunch of CPU time) that AI need to be able to perform - perception (what can the AI "see" right now?) and positioning (where should the AI stand right now?). And ironically there was a single process at the base of BOTH of those processes - raycasting. This is the geometric operation which answers the question "if I draw a line between point A and point B, will I hit anything?"

You can see why raycasting is important to perception - literally, we use a raycast from an AI's head to other objects (including the player and other AIs) to determine if the AI should be aware of them. But it's also incredibly important for positioning. Every time an AI goes through the "where should I stand right now?" process, they choose a spot from 30-50 candidate spots (given by the encounter designer) and for every one of those spots, the AI has to determine whether they have a clear line of sight to their target from there or not - no point in trying to shoot a target from the wrong side of a wall, right? So there again, it's a "is A visible from B" geometric query.

So obviously with 3D worlds as complicated as we had, answering that simple question is in fact incredibly expensive. For Halo 2, which came out on the original Xbox, we had a shockingly small number of these raycasts we could afford to do per frame - something like 12... for the entire game, for every character! Things got a little better for Halo 3, but not that much better, because of course, duh, the complexity of the world geometry was way higher, so of course the raycasts were more expensive.

Anyway, this led us to take all kinds of tricks and shortcuts, to get around the raycasting limitation. I'm talking things like "only one enemy AI is allowed to choose where to stand per frame" and "only one enemy is allowed to look at the player every frame, unless the player is actively shooting at them" etc. In the end, I think we managed to hide the rough edges, but it took a lot of gymnastics under the hood!

Nowadays not only is the hardware just way, way (way, way) better, the algorithms and data structures themselves have improved quite a bit as well (i.e. those queries are done in smarter, faster ways). So I'm really quite jealous at how many rays these young whippersnapper AI programmers are allowed to cast.

When Halo 2 came out, Bungie was adamant that experienced Halo players should tackle the game on Heroic; that that was “how the game was built to be played”. What was it about the Heroic difficulty that made it the sweet spot for the AI?

Well, to be perfectly honest, I don't know what we used to say publicly, but I think we always thought of Legendary difficulty as the best way to play the game, and that was especially true of AI. Chris Butcher and Jaime Greisemer, who worked together on the AI for Halo 1, gave a now-famous GDC talk a bunch of years ago in which they made the observation that the harder AI was the smarter they appeared - simply because the longer they live the longer they have to demonstrate how smart they are. How smart can an AI even appear to be if you can just gun them down in two seconds flat? So lots of people assumed that we added all kinds of "smarts" to the AI when on legendary difficulty, but nope, it's just the fact that they have more hitpoints, and so they live long enough to show you all the smart stuff we programmed them to do.

And it's mostly that kind of thing that makes the difference between Legendary, Heroic, Normal, and Easy. More AI hitpoints, greater damage multipliers. Really simple stuff. The way we basically balanced the game was to balance for Legendary, and then crank down those parameters for the easier levels. But really the game that we balanced was the Legendary one.

Was there anything in terms of additional behaviours that you were able to build into Halo 3 that you couldn’t in Halo 2?

Yeah, I would say that the main thing we did with Halo 3 was to scale up the encounters - we had more characters and more squads of characters (little micro-encounters of groups of three to five enemies that moved around the map as a unit) than in any previous game, and that required us to go back and change how we went about designing and programming encounters. So I think in terms of the ebb-and-flow and choreography of battle, Halo 3 was leaps and bounds beyond Halo 2.

The Marines also got more love in Halo 3. In some ways they (and all the other characters types) were also beneficiaries of the "pack" work that went into the brutes. The brutes drove us to think about the AI much more strongly in terms of groupings of characters into squads and all that means (relative positioning, verbal communication back and forth, joint behaviors, etc.) So when we beefed up the squad system, we beefed it up for marines as well, which I think resulted in the marines overall working better as a team.

Silly example, but the marines were always a bit of a disaster when it came to player-and-vehicle-oriented behavior - when they decided to get in when the player drove up in a warthog, when they decided to get out when the player got out, etc. To some extent we solved that problem by treating the group of marines in the warthog with you as their own squad, and it made their behavior as it related to vehicles way more coherent.

Unfortunately it didn't really improve their actual driving much.

Copyright © Hyper Magazine. All rights reserved.

Most Read Articles

iOS 12 hands-on: 6 things we love (and 3 we don’t) about Apple’s latest OS

iOS 12 hands-on: 6 things we love (and 3 we don’t) about Apple’s latest OS

Sony celebrates 500m PlayStations sold with translucent PS4 Pro

Sony celebrates 500m PlayStations sold with translucent PS4 Pro

Is a Nintendo Switch Virtual Console coming as Nintendo bans retro ROM resources?

Is a Nintendo Switch Virtual Console coming as Nintendo bans retro ROM resources?

Apple AirPods 2: Wireless charging case revealed in iOS 12 beta images

Apple AirPods 2: Wireless charging case revealed in iOS 12 beta images

Would you like to receive

Our Newsletter?