In taking on the world of Mad Max, Avalanche Studios set itself a tough challenge: how to recreate the manic behaviour of its inhabitants. We ask lead gameplay programmer Stefan Dagnell why Havok and madness make the perfect couple

Can AI play with madness?: Artificial intelligence in Mad Max

“It was hard to know who was more crazy: me, or everyone else.”

These words, spoken by Max Rockatansky at the opening of Mad Max: Fury Road, encapsulate the movie’s warped realm of weaponised dune buggies, bloody violence and spray paint-guzzling villains.

While Avalanche Studios’ recent game, also called Mad Max, may not be directly based on last year’s cinematic outing, it shares much of its DNA with the cult series, with skin-stripping desert winds, high-octane chases across endless sands and bone-crunching combat all coming to virtual life.

When it came to introducing some sanity to Mad Max, Avalanche turned to Havok to implement both physics and AI features. This was of particular importance for the game’s heavy focus on vehicular combat, with pathfinding and avoidance and Havok’s support for different character radii with a single set of navmeshes – from human characters to mechanical monstrosities – playing a vital role.

“Vehicle AI is the biggest new thing in Mad Max,” explains lead gameplay programmer Stefan Dagnell.

“The only way most enemies can attack is to drive their car into the player’s. This requires them to always be able to navigate successfully to them no matter where in the world they are. When doing this, they also need to take into account the other cars to not kill their allies.

“At high speeds we wanted most of the cars to be in camera view to make it more interesting for the player. This meant that the enemy cars had to be able to drive at very high speeds in front of the player without crashing into obstacles or driving off cliffs. For this we relied heavily on the navmesh and obstacle avoidance in Havok AI. Since it supports different agent radii, we could use the same mesh for the vehicles as we do for the characters.”

One of Fury Road’s show-stopping set pieces is a lengthy chase involving dozens of cars, as well as a fuel-laden tanker, that ends in flames – literally. This, too, was something that Dagnell and his team wanted to bring into their virtual world.

“The vehicle convoys are quite unique,” he says.

“They consist of a big truck with some important cargo and up to six guard cars surrounding it. The guards often need to be able to navigate around the leader, other guards and static objects to get to the player. This has to be done at speeds close to or above 60mph, on unpredictable and rocky terrain, where a single mistake often means losing control of the car. For this, we used Havok AI’s avoidance, together with some customisation provided by them.”

"If the player thinks an AI should be able to do something, then we should try to make it possible."

Stefan Dagnell, Avalanche

Players don’t spend the whole of Mad Max behind the wheel. The titular scavenger can also disembark from his vehicle to take a more ‘hands-on’ approach to dealing with enemies. That is, by punching them in the face.

“The melee aspect of the game put a much bigger requirement on successfully navigating to the player,” Dagnell reveals. “In games where the enemies – both characters and cars – use ranged weapons it’s usually fine to not be able to perfectly navigate to the player as long as you have line of sight, since it’s still possible to deal damage.

“In melee games that require physical contact with the player to deal damage, the enemies have to be able to navigate to the player wherever they are and no matter what the dynamic objects have done to the navmesh. The enemies are also much more visible, since they’re closer to the camera – which makes navigation issues less forgiving.”

A lone wanderer, Max often finds himself outnumbered when it comes to a brawl. Havok AI helped the team keep things balanced during asymmetrical combat.

“Another challenge was to figure out where each enemy character should try to position himself during on-ground, melee combat,” says Dagnell.

“You want them to spread out around the player to get a feeling of being surrounded but still avoid blocking each others’ line of sight. They should also prefer to always be able to run straight to the player if they decide to attack. For this we used the raw navmesh data and overlayed a
two-dimensional graph on top of it. Each character then calculated a score of how much he desired to occupy each node taking lots of different factors into account, such as distance to the player, other characters, line of sight, current position and so on.”

Mad Max isn’t the first time that Avalanche has indulged its more chaotic side. The studio made its name with the Just Cause series, which, like Mad Max, offers an open world to players and allows them the freedom to approach objectives as they want to. Freedom comes at a price, however, with player actions much harder to plan for during development.

“Avalanche games tend to try not to constrain the player too tightly,” Dagnell observes. “This means it is usually necessary for us to think in a systemic way, since we cannot predict all the different ways in which features or functionality will interact. That means that we need any toolset to be as customisable and flexible as possible. It is important that we can tune the level of fidelity to balance cost. We also need to be able to be able to change data representations at run-time to cater for any number of ripple effects of the player’s actions.”

Both Mad Max and Just Cause take place in environments that span for miles, with players able to roam as they please. However, Mad Max’s desolate wasteland presented a fresh challenge in contrast to Just Cause’s thriving towns.

“The most basic requirement is support for seamless streaming of the navmesh for different parts of the world,” Dagnell recalls. “The system needs to support loading and unloading different parts at any time when the game is running, as well as adding and removing custom edges dynamically. 

“Because of the vast view distance it’s important that the memory requirement for the mesh is as small as possible. We always have a fixed number of smaller patches loaded around the player, and the less memory they require the larger distance we can cover with the mesh. On Mad Max this was especially important, since there aren’t that many buildings or other objects obscuring the view since it mostly takes place in a desert.

“Automatically generating the navmesh from the game data is also a must; manually creating it and keeping it up to date isn’t feasible at all. Because of the size of the world, this step needs to be fast to avoid long iteration times. The content creators tend to be very creative in how they use the available assets, so it also needs to be robust and support objects intersecting other objects in unexpected ways and arbitrary rotations.”

Avalanche’s games have been acclaimed for their scope, but Dagnell warns that offering complete freedom means that whatever can happen, will happen.

“You have to accept that you won’t have full control of everything that happens in the world,” he advises. “If the player can block the only exit for the boss using their car it will happen, you need to make sure to handle it some way. This means that you need to rely much more on the navmesh and dynamic avoidance rather than detailed scripting from the level designers.”

"When you increase the graphical fidelity and characters look more human-like you also expect more human-like behaviours."

Stefan Dagnell, Avalanche

Mad Max marked Avalanche’s first release on the new generation of console hardware. Many players expect their games to look more visually impressive on PS4 and Xbox One, but have their expectations of AI behaviour similarly risen?

“We push ourselves at least as hard as consumer expectation pushes us,” Dagnell responds. “Engines, technology and content are crafted to mimic something that is far too complex to realise fully. As the hardware permits, we are faced with the situation where we can remove some of the simplifications or sacrifices that break the immersion the most. These can – and should be – very game specific.

“It’s also a question of what the player expects given the context. When you increase the graphical fidelity and the characters look more human-like you also expect more human-like behaviours. This is also true for the level of detail of the environment; characters that don’t interact with the environment will feel very disconnected and artificial.”

Dagnell concludes by offering his advice to those looking to raise the bar for AI implementation in their games.

“It is easy to get carried away with building AI behaviours, functionality and simulations because it seems important,” he says.

“Our experience has been that you need quite a lot of insight into what the player experience relies on and should focus on tailoring AI implementation to that.

“There is a flipside though: we often require quite a high degree of systemic thinking – if the player intuitively thinks an AI should be able to do something, then we should try to make it possible. This sometimes results in a high initial investment, but ultimately increases our ability to rapidly add new behaviors or tune existing abilities within the game. The trick is to balance these two competing forces.”

About MCV Staff

Check Also

The shortlist for the 2024 MCV/DEVELOP Awards!

After carefully considering the many hundreds of nominations, we have a shortlist! Voting on the winners will begin soon, ahead of the awards ceremony on June 20th