Skip to main content

Long read: How TikTok's most intriguing geolocator makes a story out of a game

Where in the world is Josemonkey?

If you click on a link and make a purchase we may receive a small commission. Read our editorial policy.

Making friends

Eurogamer investigates the complex world of companion AI.

Games used to be such hostile places. Dropped behind enemy lines or sneaking through monster-infested caverns, everyone you'd meet on your journey seemed to want to kill you. Over the last ten years or so, there's been a gentle rebalancing, however. From Pey'j to Yorda to Alyx Vance, designers have started giving you friends as well as enemies.

Friends - and I'm talking about AI friends here rather than good ol' co-op buddies - are hard to get right. One glitch, one twitch or one short jog against a wall, and you cease to believe in them. That's why for every game that throws in an NPC you'll remember for all the right reasons, there's another where things don't go quite as planned.

You don't need to look far to see just how tricky this sort of design can be. I'm reading between the lines, obviously, but from The Last Guardian to Spielberg's mysterious LMNO project and perhaps even Irrational's forthcoming BioShock Infinite, games that feature strong, story-supporting AI characters seem to face some fascinating challenges.

This isn't surprising, of course. It's hard enough for designers to create enemies that prioritise targets and flank properly for the minute or two in which they remain alive. Chucking in characters who stick with you for an entire game - and can, you know, act while they're at it - must be orders of magnitude more difficult.

Beyond Good & Evil proved that a huge part of building a decent companion character is nailing the catchphrase. 'Say when, Jade!' 'Carlson and Peeeeeters!'

To find out a little more about the fascinating world of companion AI, I had a chat with two practitioners of this mysterious art: Neil Wallace, a senior AI programmer from Lionhead, who's worked on everything from the creatures of Black & White 2 to Albion's villagers in the Fable series, and Ninja Theory's Tom McKeown, the senior programmer who helped make Trip and Pigsy such memorable parts of Enslaved: Odyssey to the West. I wanted to know what differentiates companion AI from the rest of games AI, and what kind of hurdles teams are up against when creating such complex characters.

"I think there's actually a spectrum of what could be classed as companion AI," suggests Wallace, when asked about how broad the field can be (and whether I'd gotten the terminology right). "You've got your guys in shooter games who are just there as back up, and then where it gets really interesting is games where the companions have more of their own personality, and more of their own agenda." Do both of these present very different challenges to, say, traditional enemy AI? "Absolutely," he says. "Enemy AI has a lot less of a thought process going on inside it. It's just thinking about the tactics of the situation. It's not thinking about how it's feeling or what it thinks of you. With companion AIs, that's what they're all about: having some sort of thoughts about the player, and thoughts about their own internal state. I guess that's what makes it difficult, and that's what makes companion AI so susceptible to going slightly awry."

The sheer range of Wallace's companion AI work has shown just how wide the spectrum is - and how tricky it can be to get even the simplest of relationships working between players and NPCs. Take the Fable series, for example: Albion's approach to interaction might lean heavily on pantomime tactics, but there are still some astonishing things ticking away in the code. "Certainly in Fable 2 and 3, the NPCs all had quite a complex system of opinions of the player on various axes," he explains (and he means axes as in the plural of axis, thankfully). "Whether they find him funny or are afraid of him, whether they loved him or hated him, whether they thought he was attractive or unattractive. These things would be based on things the player did, but then filtered through the NPC's personalities. Some of them, if you threatened them, they'd be more attracted to you - although I think that was an issue we actually chose to remove. A better example would be that some people find you being funny attractive, while other people find it unattractive."

That's AI for a relatively linear action game. Enter a sandbox and the complexity only increases. Wallace knows about this sort of thing, too, as it happens, due to his work on Black & White 2. Compared to Fable, Lionhead's god game is a far more open-ended experience, and its AI had to support that sense of playfulness. The end result was creatures that were fascinating - but often rather confusing as well.

God or no god, you'd want these weirdoes on your side.

"They were very much at the they-have-their-own-agenda end of the AI spectrum," laughs Wallace, "and it did make them unpredictable in some ways. I think that's actually what made them charming, though: they were unpredictable, so you were never quite sure which way they were going to go.

"They tried to look at how the player was playing, and they based some of their learning on those things rather than explicit feedback," he explains. "They'd look at what the player was doing, in other words, and try to base their own behaviour on that. They also had quite a complex internal state of desires that they'd try to satisfy: everything from physical desires like hunger, thirst, tiredness, to emotional things like anger, happiness, sadness. It can definitely be confusing, but a player's willingness to put up with confusion very much depends on what that character's role is within that game. Because the creature in Black & White 2 was a part of that sandbox, just finding it interesting was much more of an acceptable outcome. Whereas if that character was your partner in a first-person shooter, that would be disastrous. You want predictability and something that will support you, rather than something that's off just eating villagers and that sort of thing."

Good point. Contemporary games frequently aren't that interested in the emergent possibilities of interacting with AI, by the looks of it. They're far more concerned with allowing their audience to play through a story alongside a character that feels like a kind of virtual co-star. You don't want Elizabeth in BioShock Infinite to learn from your actions and begin looting corpses for stray cash, for example. You want her to hit her marks and help in fights and start contextually appropriate conversations. You want her to blur the lines between in-game action and cut-scenes. She's an AI actor - and this brings with it its own difficulties.

McKeown's spent a lot of time thinking about just this sort of thing. During his work on Enslaved, he was responsible for creating AI characters like Trip and Pigsy, who would be standing right alongside the player through cinematics, puzzles, and battles alike. No pressure, then.

Pigsy and Trip may look fairly different, but their AI routines had an awful lot in common, apparently.

"Trip could have been an escort mission for the entire game, and we knew people would find that hugely frustrating," he says. "In response to that, we didn't try to do anything too cutting edge with AI. We wanted everything to just be really robust, and then you wouldn't end up creating situations where you couldn't get Trip to do the things that were required and so you ended up getting annoyed with her. That was the key to it, really."

McKeown raises another interesting issue: getting an AI character to feel right seems to be something of a balancing act. Make them too weak, and the game turns into that dreaded escort mission. Make them too powerful, and you risk reducing them to the status of a chatty kind of smart-bomb - a hero lurking down on the D-Pad for when times get tough. "That's a big part of the challenge," he says. "Trip was always intended to be a weaker character that you would have to help through the game, and we didn't want to put too much into her abilities for that exact reason. The powers we gave her in the end were more to prevent player frustration - that's where her EMP weapon came from. It's a last ditch effort if you do make a mistake."

"Trip could have been an escort mission for the entire game, and we knew people would find that hugely frustrating."

Tom McKeown

Beyond that, and even with the studio reining itself in, Trip still highlights the challenges inherent in having an NPC around for so much of a game. "There are long sections where AI characters are playing without any enemies around," explains McKeown, "and you want to have different behaviours to make them more believable in those situations. Then, in situations where there are enemies around, self-preservation should take over. There are certainly more behaviours with this type of AI, and it's crucial to get each and every one of them robust so that you can avoid that frustration.

"For me one of the most important things that we spent a lot of time trying to get right was character movement alongside the player," he continues. "In some games you kind of see a shuffle: the player moves and then everyone follows that exact line in single-file. That was something we really tried to avoid. As much as possible, Trip's trying to run alongside Monkey and actually be on camera. That was something that was quite important for us, and perhaps not what you see in a lot of games with a buddy character."

Elizabeth promises to be one of the most fascinating aspects of BioShock Infinite. That only raises the stakes for the coders and animators, though.

Complicating matters, of course, is the fact that AI frequently needs to be blended with scripting - with moments where the designers drop in and take more direct control of companion characters. This is particularly crucial for games that involve complex storytelling and set-pieces - and with sophisticated AI, everything can become a set-piece if you're not careful.

"This moment's always difficult," admits Wallace. "What happens is that you generally almost turn off the AI completely as they go up their script control path and do what they need to do, and then they're released back to their AI.

"Sometimes it's more complex, though," he adds. "In Fable, you might say, "this guy isn't able to fight, but he is able to flee," and offer some quite high-level controls over the AI when necessary. In general, though, when you need that level of control, it's best to shut down AI completely. Otherwise the two systems will just be fighting each other for control."

These changeovers often become moments where the cracks start to show, and they raise a question that strikes at the heart of the problems that AI designers face. Is there an uncanny valley for AI? Is there a moment where you get so close to seeing an AI as a convincing character that even tiny glitches become disproportionately jarring?

"Absolutely," sighs Wallace. "And I think the big issue in AI is that there's a general lack of fluidity when moving from one action to another: they'll walk to a point, they'll turn to face an object, they'll do something with that object, and it's all very robotic and very staccato. I think moving forward one of the big challenges is going to be getting some of that really nice fluid movement, where they look like they're going to do something with a particular purpose in mind, rather than it being a case of every time they walk somewhere, they walk there in the same sort of manner." So the big leaps need to be in performance as well as behaviours? "Yes! One of the things I didn't really appreciate about AI before I worked in the field was that I didn't realise how involved animators are in the process, and how inspiring they are in terms of the way they look at the world. Just walking to a point isn't just walking to a point. It should be telling you something about how that character is feeling, and what they're intending to do."

"I think the big issue in AI is that there's a general lack of fluidity when moving from one action to another."

Neil Wallace

"Animation is really crucial to getting the characters right," agrees McKeown. "There's no point putting any AI systems in if there isn't some feedback to the player regarding what's happening, You've always got to have something going back to the player to let them know what Trip or Pigsy are actually thinking in a way. In terms of making characters believable for us, a lot of the work for that was actually done with the mo-cap and with getting the cut-scenes right. Then it was just following through and having the same style of character in everything Trip does."

So how close are we to the point where AI characters will be truly convincing on a regular basis? "It's difficult to say," says Wallace. "We're definitely moving in the right direction, and there's a lot of really interesting work being done on the animation system side of things to support that. There seems to be a real uptick in design interest at the minute, too. It's really hard to predict which way things are going to go, though. It's definitely an area I'm interested in pushing forward, but it is tricky. The more you get pure AI, the more there's an inherent unpredictability in that."

And as a designer, do you want to preserve a bit of that? "Absolutely," Wallace laughs. "When you're dealing with a human being, part of the fun is that you can't tell 100 per cent what they're going to do or what they're thinking. I guess it can be unpredictable, but you still need to be able to understand in the end why it's chosen the thing it's chosen."

Great mo-cap helped Ninja Theory bring Trip to life.

I ask both Wallace and McKeown if there's one AI issue they'd really like to be able to solve, or one aspect of the craft that is still holding everything back. "For me, I guess it's the subtle things," says McKeown. "We can get the behaviours right that are needed for the gameplay right now, but if we can add subtle features to it that you would get from a real person, that's where the believability comes from. Trip has quite a nice thing where - if she's completely safe with no enemies around - she'll look at interesting parts of the environment. Then, in a feature that had to be cut towards the end of development for robustness, we had a feature where she would wander off and just sit on bits of scenery. We had to drop that, but things like that are really nice when you see them working. I wanted her to back off if the player got too close, and respond to the player in that kind of subtle way rather than just responding to commands from the player."

Wallace, meanwhile, is more interested in the deeper processes taking place inside the AI character's head. "It's less of an absolute problem and more of a sliding scale," he says. "I guess what separates interesting AI from uninteresting AI for me is that uninteresting AI is very reactive. It doesn't think ahead very far. Interesting AI is where you get more to the planning of a sequence of actions, rather than each action being a reaction. It's just something that's deliberative. Something that has more of a long-term goal, rather than just instinctual behaviours. Imagine an AI that has a goal that may take days, weeks, months to get to, but where it's constantly trying to move in that direction.

"Added depth, I guess, is how I'd summarise it."

Read this next