Hi I'm Tommy Tompson and this is AI and Games, a series on research and applications of artificial
intelligence in video games. In this video we return to the world of Far Cry to look
at one of the core mechanics of 2016's Far Cry Primal: animal taming. In Primal players
can lure and tame a variety of predators to later use as weapons in combat. It's a fun
new system to add to the Far Cry formula, but it's introduction was far from straightforward.
So let's take a look at how the companion AI works in Primal and the steps taken to
ensure it operates in and around the systemic AI Far Cry is known for.
As detailed in an earlier video in the series, Far Cry is built atop a systemic gameplay
framework: where numerous systems and mechanics interact with one another and enables emergent
gameplay to arise. What that means is that you can get a tiger to attack an outpost while
you're throwing C4 on them from a fucking helicopter and the c4 blows up a jeep that
that flies through the air and takes out that one guy who was gonna call for reinforcements.
BOOM, there's your $60 investment right there.
There are numerous AI systems involved in making this happen: the friendly NPCs, the
enemies soldiers, cars, honey badgers... little shits - and yeah all the other wildlife too.
So speaking of wildlife, where do the companions come into play?
So, while Far Cry is built primarily at Ubisoft Montreal, the companion AI in Primal was developed
by a small team at Ubisoft Toronto. It wasn't their first foray into Far Cry, having been
brought in to assist development on Far Cry 4 after the launch of their inaugaural title
Splinter Cell: Blacklist in 2013. Toronto were responsible for building the Shangri-La
sequence in Far Cry 4: a series of five linear missions within the game in which the player
trips out on some weird-ass drug cocktail and finds themselves on the path of Kalinag
the Seeker fighting demons dogs and a giant bird. In these levels, the player befriends
a tiger that they can use as a weapon and clear out enemies - that's right kids, you
get a tiger gun. As Far Cry 4 wrapped development in 2014 and Primal moved into pre-production,
Toronto pitched to Montreal that they would expand this one-off feature and turn it into
one of the core mehanics of the new game. However, this brought with it a stack of new
problems that were never encountered during the development of the Shangri-La sequence.
As already described, Far Cry carries numerous systems (several of which in the AI itself)
as part of the systemic gameplay experience. However Shangri-La is a series of linear missions
with very specific hand-built and crafted sequences. As a result, almost all of the
systemic AI is disabled and the behaviours of the tiger were heavily customised to allow
it fit within the narrative playing out. However, the companions are Primal are expected to
operate throughout a game where all the systemic shenanigans are in full force. As such, many
of the existing systems that they had built for the Tiger didn't transpose directly across
to Primal and in fact an entirely new system was put into place.
To build the companion system, Ubisoft took a step back to consider two key aspects:
First up, what is the fantasy they're trying to sell? In this case the idea of the player
being the beast master that can literally throw bears at their problems.
Secondly, what is the role of the companion? To do this they considered how the animals
would support the player and took inspiration from the likes of Dog Meat from Fallout 4
and Elizabeth from BioShock Infinite, a topic I've already covered on AI and Games. Animals
act as both companions on the hunt across the plains of Oros Valley but also as a collection
of diverse weapons players can throw into combat scnearios and turn the tide of combat.
Far Cry Primal is essentially a mesolithic period reboot of Pokemon, only with more teeth
and lot more collectables on the minimap.
During initial development there were over 50 animals prototyped as companions, pretty
much any animal from previous Far Cry games were toyed with as a potential weapon. However,
given the production schedule implied Ubisoft wanted to launch the in two years this century,
they scaled it from 50 down to 17. This sadly meant cutting what sounded like impractical
but fucking awesome companions that reached prototype, including a chicken and a freaking
turtle. Sure they might be useless in combat, but they would have been my blood brothers
in the war on terror...
So how do they work? All of the AI in Far Cry is built using behaviour trees: a technique
that has cropped up in my videos on Halo 2, Alien: Isolation and Spec Ops: The Line to
name a few. These trees are built using design tools that encode them entirely in XML. The
team in Toronto were wary of coming on board to start messing around with the existing
code base, not just because it could cause conflicts for the teams in Montreal, Shanghai
and Kiev who also worked on the game, but also because of the sheer number and scale
of these systems. This would require them to edit dozens of existing behaviour trees
already established in the Far Cry code base. But then that presents a new problem, the
new companion behaviours would often contradict the systemic AI behaviours that already exist.
So how do they address this?
The solution is a system referred to as dynamic behaviour tree injection: the game at runtime
injects a new micro behaviour into the system based on the command the player has given
to the companion. This solution required little effort to introduce into the existing Far
Cry AI architecture, plus new companions could be prototyped in a couple of days given any
animal could be extended to support the injection system. Perhaps most critically, it meant
that the Toronto team could focus on refining the behaviours without worrying whether the
Shanghai office would wake up the following morning only to discover the entire behaviour
tree system was broken.
So how does this balance out with the existing system? After all, the companion behaviour
is directive from the player, while the AI already operating in each animal is an emergent
and responsive system based on the world around it. It needs to do what you tell it to do,
so as not to annoy First of all each injected behaviour tree
dictates what priority it has over existing ones. Hence, they would ignore things they
may typically react to. But conversely, it also permitted for certain instinctual responses,
such as the fear of death, to interrupt or overrule the injected behaviour. Hence while
you might tell your tiger to run towards a chosen location, it won't run through fire
and burn itself alive to satisfy your request, but it will return to operating in systemic
AI mode once it has reach the destination.
Secondly, systemic behaviours can be disabled entirely if it doesn't suit what the companion
behaviour requires. This is useful in some instances given that your beast master actions
aren't really in the best interests of the animal, such as sending smaller animals to
fight larger ones in combat.
This retains a sense of empowerment in the mechanics - and the fantasy the game tries
to sell - by smartly and cleanly overriding all of the existing AI systems.
Interestingly, maintaining the fantasy is the reason one of the most notable mechanics
with the companions - the ability to pet them - is kept in the game. Petting a tamed animal
has absolutely zero impact on the AI behaviour or its relationship with the player. Ubisoft
just knew people would get a kick out of it.
But despite all this care and attention, there were still some very real problems to solve
in the game. So let's look at the tricks used to keep the power fantasy on track.
There were two specific issues that the companion AI team had to contend with in Primal: how
companions stay within proximity of the player and how do they follow you when you're on
the move. This actually caused a number of problems given the team wanted to ensure that
your companion should always be with you at any point in time, but sometimes the navigation
meshes in the game world don't provide a valid path or you've done something ridiculous like
just off a high cliff. So how do they compensate for that?
So keeping the companion in proximity is done the easiest way possible: it teleports, but
only if it's not within the players field of view for more than a couple of frames and
it's too far away to reach you quickly. Should the animal be too far away, the game begins
to sample locations behind the player that are valid for the companion to spawn onto.
That way you don't have a bear spawn on a tiny rock, or a sabretooth tiger spawning
in a river, given they can't swim.
While in the retail build this happens very infrequently, you can catch it in the minimap
in the bottom corner in very specific circumstances.
Secondly, when companions are following you, they try to stay in your field of view, but
not directly in front of you. Thus ensuring that they're not blocking your view of the
path ahead, but also you don't have to worry about staring at a bears arse for 10 hours
of gameplay. Given each animal has its own custom animations set, each has to handle
how they move on each frame and adapt the animations to suit based on whether you're
idle, walking, running or even in stealth mode. All animals run at approximately 130%
of the players running speed when in field of view, but they move at 250% of your speed
when you can't see them. Thus ensuring they're never too far behind you if you run off without
them.
However, this creates a very specific problem that the Toronto team nicknamed 'slingshotting',
where if you get far enough away from your companion, it will come screaming up behind
you and if you stop the animal will keep moving for a time until it slows down. This created
a very real problem during testing where if the player stops suddenly near a cliff edge,
the animal couldn't slow down in time and would throw themselves to their doom. The
first solution to this was to make them respawn and teleport in after they fell from view
- effectively resurrecting a dead companion so as not to punish the player for the animals
mistake. But tiger base jumping broke the immersion. To address this, animals frequently
conduct raycast checks around them to calculate distances to nearby edges and can apply speed
reduction multipliers (or as we call them, 'brakes') to the movement code, which solves
around 90% of these instances in the final game.
While it proved a minor detour from the traditional Far Cry formula, Primal's companion AI was
a fun extension that provides some cool and engaging gameplay. It subsequently returned
in much reduced capacity in Far Cry 5, with a handful of animals available as companions.
Perhaps we'll see more of these systems - and Far Cry itself - on AI and Games in the future.
Hey everyone, thanks for watching this video on Far Cry Primal.
I threatened I was gonna talk about this stuff waaaaaaay back when I launched my Far Cry
4 video almost two years ago and now thanks to these lovely patrons right here who voted
for it, I made good on my promise. Special thanks to Chris Seddon from Ubisoft Toronto
for his awesome nucl.ai talk that this video is based on and for some fun chat we had at
the time when we met a couple years back.
In the next patron-voted topic, we're stepping back into the boots of Master Chief Petty
Officer John 117 as we take a look at how Halo 3's AI handles large-scale combat sequences.
In the meantime, please like, subscribe, share the video, join the patreon, bang the drum
and spread the word on AI and Games. I'll see you again soon!