GameDev

The Last of Us's AI Breakdown

The Last of Us's AI Breakdown

Learn: The Game Designer Profession from Scratch to PRO

Learn More

The first season of The Last of Us recently concluded. Both viewers and critics praised the HBO adaptation, emphasizing that the creators managed to preserve the general mood of the original game. However, the transition from a video game format to a cinematic one inevitably affected the dramaturgy, as a result of which the adapted work lost some aspects related to the gameplay and interaction with virtual opponents.

An article from the editorial board of Gamedev Skillbox Media is dedicated to how Naughty Dog, the developers of the original game, used enemy artificial intelligence to create gameplay tension and a sense of realism. Game development requires not only creativity but also a deep understanding of the technologies that can enhance gameplay. Naughty Dog demonstrated how the right use of AI can significantly increase player engagement, creating exciting moments and enhancing the game's atmosphere. Importantly, thoughtful enemy design and behavior not only contribute to evoking emotion but also to creating a unique gaming experience.

The Foundation of Artificial Intelligence

Creating the AI ​​for The Last of Us presented a real challenge for Naughty Dog. The developers were forced to develop numerous systems from scratch, as the company's previous projects rarely included stealth elements. As Travis McIntosh, lead programmer at Naughty Dog, notes, the stealth mechanics in the Uncharted series were rather primitive: "Stealth was there, it was fun, but if it didn't work right, we just ignored it."

Screenshot: Uncharted 3 game: Drake's Deception / Naughty Dog

In the first three Uncharted games, NPCs didn't have a state of alert between calm and aggressive. As soon as an enemy spotted Drake, a firefight would immediately begin. In contrast, The Last of Us requires a more thoughtful approach to interacting with enemies. Players must take NPC behavior into account, which adds depth and realism to the gameplay.

Artificial intelligence in stealth games relies on key components such as NPC hearing and vision, as well as algorithms for finding the optimal route in various gameplay situations. While some of these systems were new to Naughty Dog, they are familiar to most developers working in the stealth genre. Effective implementation of these elements allows for more realistic character behavior and enhances player engagement with the game world.

In The Last of Us, NPCs detect the protagonist only when they enter their cone-shaped field of view. This classic form of vision is widely used in gaming genres because it is easy to implement and provides an intuitive gameplay experience for players. This approach creates a tense atmosphere in which players must consider enemy placement and act cautiously to avoid detection. Understanding NPC visibility mechanics correctly is a key element of in-game strategy.

Standard vision cone in stealth games Source: Game Developers Conference. Infographics: Maya Malgina for Skillbox Media

A linear approach to game design has its drawbacks. The narrow base of the visual cone allows the hero to be just a meter to the left or right of an enemy's line of sight and remain undetected. To improve detection and make it more realistic, the developers of The Last of Us expanded the area at the base of the cone, simulating peripheral vision. This approach has become increasingly common in the gaming industry. For example, it can be seen in games like Splinter Cell: Blacklist and Deus Ex: Mankind Divided, demonstrating its effectiveness in creating a more immersive gaming experience.

Cone of Vision in The Last of UsSource: Game Developers Conference. Infographics: Maya Malgina for Skillbox Media

To check whether the enemy has detected the hero, the developers use a raycast system. An invisible beam is generated from the NPC's head and directed at the player. If there are no obstacles in the beam's path, the enemy's invisible detection indicator begins to fill. The closer the player is to the NPC, the faster the indicator fills. This system allows for more realistic interactions in the game, ensuring dynamic NPC behavior and increasing the player's immersion in the gameplay.

The raycast system has an interesting aspect: when enemies are idle, the beam is aimed at Joel's chest by default, and during combat, it is aimed at his head. This feature is necessary to ensure that the gameplay situation meets user expectations, as the character is always physically visible, even when hiding behind cover—Joel's arms, shoulders, and parts of his weapon may protrude beyond the boundaries of the object he is behind. Using a single ending point for the ray could lead to an imbalance in gameplay, both in stealth and in open combat.

Ray placement in different game scenarios Source: Game Developers Conference. Infographics: Maya Malgina for Skillbox Media

In early versions of The Last of Us, the developers sought to implement a more realistic raycast system. The beam was envisioned to detect the hero dynamically, reacting to different parts of their body at different speeds. For example, colliding with Joel's hand would cause slow detection. However, after playtesting, this mechanic, which seemed promising on paper, was abandoned. Players didn't always understand the reasons for their detection, which negatively impacted gameplay.

Naughty Dog actively used artificial intelligence in their projects, but some ideas, including the one described above, were rejected as a result of playtester feedback. This highlights the importance of testing and feedback during game development, allowing the team to optimize game mechanics and improve the overall user experience.

How do other developers approach this challenge?

Creating an effective detection system in games that takes into account game conventions is a complex task. Naughty Dog's solution works, but it includes limitations that can constrain game designers' creativity. In contrast, Ubisoft's programmers developed a more elegant system in Splinter Cell: Blacklist. This system uses multiple raycasts for detection, rather than a single one as in The Last of Us. These raycasts are directed at different parts of the protagonist's body, allowing for a more realistic and dynamic interaction with the game world.

Naughty Dog's system has its own quirks. For example, if an NPC only notices the top of a character's head while hiding behind cover, they won't react. This happens because only one beam of light captures the top of the head, and this is not enough to detect the character. This makes gameplay more realistic and engaging, as NPCs don't respond to minimal visual cues, creating additional tactical opportunities for the player.

This mechanism not only eliminates temporary solutions but also allows for flexible detection speed adjustments for different enemy types. For example, keen-eyed snipers can spot a hero with fewer beams hitting their figure, while ordinary soldiers require more beams to detect them. This allows for more strategic gameplay that takes into account the behavioral characteristics of each enemy type.

To ensure NPCs can navigate the game's environments correctly, developers often use invisible navigation meshes. Naughty Dog also uses this approach in The Last of Us. Navigation meshes not only define level boundaries but also prevent NPCs from using cover, eliminating situations where enemies attempt to pass through objects. This provides more realistic behavior of characters and improves the overall gameplay.

Almost all navigation meshes work on the same principle: each individual mesh covers a horizontal section of the location and, if necessary, has an intermediate node for linking to another mesh, for example, if the meshes are at different heights. Navmesh in UnityImage: Unity

To ensure natural enemy movement in the game, Naughty Dog developed a unique navigation map. It can be thought of as a reverse navmesh: a grid that marks impassable objects and a small area around the character for the AI. When an enemy needs to move to a specific location, its route is generated based on the navmesh and then adjusted in real time using the navigation map, which contributes to more realistic AI behavior.

Navigation mapImage: GDC Vault

For effective Artificial intelligence requires information about the characters' movement directions in various scenarios. A navigation mesh is used to place outposts—points located both in cover and in open spaces. Depending on the tasks facing NPCs, they plot their routes through these points. A single character can analyze approximately 30 points in their surroundings several times per second, significantly increasing the realism and adaptability of gameplay. For example, an NPC may choose the shortest route to investigate the source of an abnormal noise. In other cases, a more complex algorithm is used, especially in combat scenarios. When a threat arises, the enemy doesn't always rush to the nearest cover, as it may be vulnerable to Joel's bullets. In situations with multiple criteria for optimal pathfinding, the appropriate route is determined using real-time calculations. This allows NPCs to make smarter decisions that take into account not only the distance but also the safety level of cover, which significantly improves the realism of the gameplay.

Code for evaluating a suitable post in a panic state. In this case, a rating is calculated for each post in real time. The character selects the point with the highest value. In addition to the numerical values, there are strict criteria: if a post exposes an NPC to the player in a combat scenario, it will not be selected under any circumstances. Image: GDC

Features of Artificial Intelligence in The Last of Us

The systems described above are the foundation of most stealth games. To create a unique gaming experience, additional elements are needed to realize the developers' creative ideas. In The Last of Us, the team aimed to create truly living opponents who would be unpleasant to kill. The development of human AI began with a key question: "How can we convince the player that their opponents are living beings so that the process of destroying them causes discomfort?" The answer to this question informed the entire design of the game's enemy AI, significantly enhancing the emotional impact and adding depth to the gameplay. Achieving this goal relies heavily on the work of animators and voice actors. However, flaws in AI can quickly ruin the impression of believable character behavior. To avoid such problems, the developers focused on the basic actions of enemies. It is important that enemies do not simply seem inept. Characters become more realistic when they are positioned correctly, respond appropriately to the player's actions, have convincing animations, and have voice acting that complements their actions. This creates a more immersive and captivating gaming experience. In The Last of Us, characters make decisions based on a unique system that classifies NPC actions into three main categories: abilities, states, and behaviors. This system allows for realistic interactions between characters and the environment, significantly enriching the gameplay. Skills determine how characters react to various situations, states reflect their emotional and physical state, and behaviors guide their reactions depending on the circumstances. Thus, each encounter with an NPC becomes unique and unpredictable, adding depth and tension to the game's narrative. Skills represent complex, high-level skills, such as combat, that require the AI ​​to perform a series of simpler actions. These skills can have different states, such as combat being overt or stealthy. Each skill consists of several basic actions or behaviors. In the context of combat, it is important for NPCs to be able to move, aim, shoot, and perform other actions, which allows for more realistic and dynamic interactions within the game environment. Developing such skills requires a detailed approach to programming and designing character behavior, which significantly improves the quality of gameplay.

The diagram according to which NPC actions are divided in The Last of Us Source: Game Developers Conference. Infographics: Maya Malgina for Skillbox Media

Unpredictability and Danger

In The Last of Us, the developers strove to create an atmosphere of danger and unpredictability, which is clearly reflected in the gameplay mechanics. AI-controlled enemies shoot with high accuracy, and the weapons they use inflict significant damage on Joel. Each hit limits his movement and leaves him vulnerable. Even a single enemy can pose a serious threat to the player, which emphasizes the need for a strategic approach in battles.

Screenshot: The Last of Us / Naughty Dog

When there are two or more opponents, the difficulty of the situation increases, which can lead to To the point that the game becomes virtually unplayable. To solve this problem, a limit on the number of enemies firing simultaneously is often used. This method is used in a number of games, including Uncharted. However, in The Last of Us, this approach sometimes leads to absurd situations where multiple enemies target the protagonist but do not open fire. This can reduce the tension and realism of the gameplay, creating a dissonance between player expectations and the characters' actual actions.

To achieve an optimal balance between difficulty and realistic behavior, a role coordinator system was implemented in the game. This system distributes tasks among non-player characters (NPCs), effectively acting as a link between their desires and actions. For example, if an enemy intends to flank Joel, they approach the coordinator for the appropriate role. The coordinator checks the availability of this role and makes a decision, approving or rejecting the NPC's action. This mechanic not only improves character interactions but also increases player immersion by creating a more dynamic and realistic gaming environment.

Enemy Roles

In The Last of Us, human enemies have approximately five different roles, each with unique skills. This variety of roles makes battles more interesting and dynamic. The Role Coordinator ensures that the required level of difficulty is maintained, which adds depth and strategy to the game.

The Flanker is the most unpredictable enemy type in the game. Their tactic involves flanking Joel to catch him off guard. To successfully execute this strategy, the NPC must be aware of what the player is seeing. This is aided by the detection and elevation system, which displays in real time on the navigation mesh all areas accessible to both the player and their enemies. This mechanic adds an element of strategy to the gameplay, making interactions with the Flanker more challenging and interesting.

The flanker skill requires more than just basic mechanics to be effective. During combat, the player may become distracted or their view may be obstructed by obstacles. This creates an opportunity for the flanker to attempt to outflank Joel by moving directly toward him. To prevent such situations, the developers implemented a combat vector, which analyzes the firing direction of both the player and their opponents. As a result, NPCs with the flanker skill are tasked with approaching the player through cover located outside the combat vector. The further the cover is, the higher the flanker's score. This approach makes the gameplay more dynamic and strategically complex, which enriches the player experience and enhances interaction with NPCs.

Screenshot: The Last of Us / Naughty Dog

The game's enemies create a sense of constant tension and push out the hero out of their comfort zone. For example, an NPC acting as a checker will move to the hero's last known position if the latter takes a long time to emerge from cover. This is an interesting example of how artificial intelligence can use unconventional methods to enhance gameplay. The presence of such elements makes the game more engaging and requires the player to be more attentive and strategic.

Enemies in the game generally act fairly and have the same understanding of the combat situation as the player. However, in the checker role, the system tracks the distance Joel has traveled from his last known position. If he is five meters or more away, the checker quickly moves to the desired point to speed up the battle. Otherwise, the player has the opportunity to carefully flank enemies, which can lead to unbalanced gameplay.

A role known as an advancer is used to gradually move an enemy toward the hero. This strategy is often used in conjunction with another role: while one enemy moves to the next cover, their partner maintains surveillance, ready to support the fleeing character if a threat arises. This movement tactic, based on real-world military principles, is called "Bounding Overwatch." Using such strategies in gameplay not only increases the level of interaction between players, but also promotes a deeper immersion in the tactical aspects of the game.

Schematic representation of Bounding Overwatch tactics. Infographic: Maya Malgina for Skillbox Media

The remaining two enemy roles—the marksman and the aiming marksman—typically remain stationary and watch the hero closely, waiting for the moment when he emerges from cover. These enemies play an important role in the game's tactical component, creating tension and requiring caution and strategic thinking from the player.

Interestingly, the appearance of the marksman in the game was spontaneous. The developers noticed that, due to the wide variety of roles and complex animations, enemies sometimes spent time acting realistically instead of attacking Joel. To solve this problem, Naughty Dog introduced a new role in which the enemy is always waiting to shoot Joel. The coordinator assigns one such marksman to each combat situation, making battles more dynamic and tense. This solution significantly improved the gameplay by adding a strategic element to enemy AI.

Customization of Individual Battles

To increase the variety and unpredictability of battles in The Last of Us, the developers implemented a system of adjustable combat parameters for each enemy. This gives designers the ability to adjust NPC behavior at any time, increasing their aggressiveness or, conversely, making them more cautious. As a result, each battle becomes unique and memorable, significantly increasing the interest in the gameplay.

Customization applies not only to enemy classes but also to unique NPCs in specific locations. This means that two seemingly identical, difficult opponents can demonstrate different tactics and behavior depending on the environment and game conditions. This approach adds variety to the gameplay and makes each encounter with an enemy unique.

Code for setting the combat parameters of one of the enemies with a shotgun. Here you can see that the NPC is prohibited from flanking the hero and hiding in cover. The desired distance to the target is from 10 to 40 meters. Outside this range, the enemy will try to increase or decrease the distance. Image: GDC

Stealth

In The Last of Us, the player experiences a sense of danger not only in combat encounters, but also during stealth moments. This feeling is enhanced by challenging gameplay situations and the high level of intelligence of enemies, who effectively track the hero. The player must use strategy and courage to overcome threats, which adds depth to the gameplay and creates a tense atmosphere.

In stealth games, enemies react to sounds, which makes the gameplay more tense and interactive. Every object that the player can touch creates a sound event. If an enemy hears this sound, they go to the nearest outpost to determine the source of the noise. However, if several enemies have heard the sound, the role coordinator is activated: they select one of the NPCs to check the situation, ignoring the others. This mechanic adds a strategic element, as the player must pay attention to sound effects and enemy actions to successfully complete missions.

Searching for the player is more complex and requires a thoughtful approach. To enhance its credibility and effectiveness, a map-based search system is used. Once the hero disappears from enemy sight, an invisible field is created around their last known position on the navigation grid. If enemies are unable to locate the hero, they begin clearing the area indicated on the map using the detection map described earlier. After a period of unsuccessful searching, the characters return to a dormant state. This search mechanism contributes to the creation of a tense atmosphere and requires attention and strategy from players.

Search MapImage: GDC

Artificial Intelligence of the Infected

The artificial intelligence of infected opponents is based on Similar principles govern pathfinding and behavioral patterns. The infected use navigation systems and posts, and their actions are controlled by a unified system that categorizes their behavior into skills, states, and actions. This allows for the creation of more complex and adaptive behavioral strategies, making their interactions with players more realistic and unpredictable. The behavioral patterns of the infected differ significantly from those of normal opponents. Runners and clickers lack focus; their actions are chaotic and spontaneous, driven by survival instincts. Infected enemies also differ physically from healthy humans, which alters the functioning of their senses. These changes make them more aggressive and unpredictable, which poses a serious threat to survivors.

Screenshot: The Last of Us / Naughty Dog

The infected have serious vision problems and rely primarily on their developed hearing. For example, clickers have, on average, six times more acute hearing than humans, allowing them to react to sound cues more quickly and accurately. This makes them dangerous opponents, as they can detect people by sound, significantly complicating the task of surviving in their presence.

The enemy target search mechanism has its own unique features. Several infected can simultaneously check the source of a noise. This is done using a special skill called following. One of the infected can "attach" to the one searching for the hero. If the target is not found at the designated point, they continue searching, but do so differently than humans. Instead of searching the area on the map, they perform a cursory glance animation. Enemies have multiple animations for examining different parts of the location, but only one is selected that covers the largest portion of the unknown territory at a given moment. This approach makes their searches more effective and unpredictable, adding tension to the gameplay.

The algorithm for selecting a suitable search animation. In the fourth image, you can see that the infected has two different animation options: one covers 10 new visible sectors, the second - 18 / GameAIPro Source: Mark Botta. Infographics: Maya Malgina for Skillbox Media

Infected creatures exhibit unique behavior patterns that differ from humans. When calm, they are capable of not only following predetermined routes, but also moving randomly. This aspect emphasizes the chaotic nature of their actions. The ability to randomly move is activated in infected when they do not detect the hero after checking the source of the noise. Returning a blind clicker to its previous patrol route in such a situation would be illogical.

Disadvantages

The artificial intelligence in the original The Last of Us was an impressive achievement for its time, however, a deeper analysis can also reveal its shortcomings. The developers admitted that limited development time did not allow for the implementation of some of the intended ideas. These limitations, in turn, impacted NPC behavior and interactions with the game world. Despite this, The Last of Us managed to set high standards for AI in video games, leaving a significant mark on the industry.

Travis McIntosh admitted in 2014 that the studio failed to implement the combat mechanics between healthy humans and the infected in time. He noted that one of the main problems was the numerous assumptions in the code related to the player. Once the team addressed these limitations, it took only a few weeks to implement the mechanics. If this feature had been considered from the very beginning of development, its implementation would have been possible at an earlier stage.

Battles between humans and infected were eventually implemented in the Left Behind add-on. Screenshot: The Last of Us Left Behind / Naughty Dog game

In some cases, Naughty Dog didn't have time to refine already implemented mechanics. For example, all enemies had a unique "hide" skill that activated when the last enemy left in the arena without a firearm. In such situations, the combat coordinator forced NPCs to flee to the farthest point from Joel. Due to the many conditions, it is extremely difficult to notice this behavior in combat, and it can only be truly appreciated during the battle with David.

Screenshot: The Last of Us / Naughty Dog game

AI improvements in The Last of Us Part 2

The sequel to The Last of Us sees significant changes in the area of ​​artificial intelligence. New enemy types, including dogs, make the gameplay more complex and multifaceted. These innovations not only increase the level of difficulty but also add new tactical elements to the fight against enemies. Players will have to adapt to changing conditions, making each encounter unique and tense. The development of AI in the sequel improves the overall gaming experience and immersion in the world of The Last of Us.

Naughty Dog has not yet revealed details about the artificial intelligence in The Last of Us Part 2, making it difficult to fully understand its mechanics. However, there are reports of significant changes that have been implemented in the sequel. Improved artificial intelligence will likely affect the behavior of NPCs and their interactions with the environment, which will make the gameplay more realistic and engaging.

With the transition to a new generation of consoles, the sequel has managed to eliminate a number of limitations, significantly improving gameplay. In particular, an unlimited number of enemies can now participate in combat. In the original game, due to the technical limitations of the PS3, the number of active enemies was limited to eight, while the rest played passive roles so as not to overload the system. In Part 2, this limitation is eliminated, which makes battles more dynamic and intense. This same innovation was applied in the remake of the first part for PS5 and PC, allowing players to enjoy larger and more exciting battles.

The second important change, which harmoniously fits into the design concept of the series, is that alarmed enemies no longer return to a calm state. Instead, they continue to constantly search for threats. This innovation increases tension and makes the gameplay more dynamic and exciting.

Changes to the artificial intelligence of The Last of Us Part 2 can only be assessed based on practical experience. YouTube users noticed that enemy characters now use more varied animations while patrolling. This makes it difficult to approach them undetected, adding a new level of complexity and realism to the gameplay.

The artificial intelligence in The Last of Us effectively creates engaging gameplay situations and advances the storyline. Combat scenarios highlight one of the key themes of The Last of Us: even in situations where people must unite, everyone has their own reasons for violence, often rooted in fear and the desire to protect loved ones. This cruelty and unpredictability of human nature make people more dangerous than other creatures.

Reading is of great importance in our lives. It helps to broaden our horizons, develop our thinking and improve our communication skills. It is important to choose high-quality sources of information to obtain relevant knowledge and ideas. Regular reading of books, articles and other materials contributes to personal growth and enrichment of the inner world. Don't forget about the diversity of genres and themes to make the process more engaging and rewarding. Read, exchange opinions, and discuss what you read with others. This not only develops critical thinking but also deepens your comprehension.

Twice in the same river: the Resident Evil 4 remake and its desire to repeat the success of the original

The Resident Evil 4 remake is an attempt to recreate the magic of the original game, released over 15 years ago. The creators strive to preserve the key elements that made the game iconic, while adding modern graphics technology and improved gameplay mechanics.

The original Resident Evil 4 revolutionized the survival horror genre with its immersive atmosphere and innovative controls. The new remake aims to attract both old fans and new audiences, preserving the spirit of the original but updating it for modern platforms.

Modern technology allows developers to improve graphics, add new details to the environment, and rework character animations, creating a more immersive gaming experience. The remake also includes changes to the storylines and mechanics, adding freshness and intrigue to the familiar story.

Comparisons to the original are inevitable, and critics are already discussing how well the remake achieves this. One key aspect that remains in focus is the balance between nostalgia and novelty. The developers strive to meet the expectations of fans, while not forgetting that the new version should be attractive to a new generation of players.

Thus, the remake of Resident Evil 4 not only tries to repeat the success of the original, but also sets itself the task of reimagining the classic game, ensuring its relevance in the modern gaming world.

Profession Game Designer with From scratch to PRO

A game designer creates the structure of a game. They develop the concept, rules, and gameplay, and decide what emotions the story will evoke in players. You'll master the principles of game design from scratch and learn how to work with the popular Unity and Unreal Engine. You'll learn how to keep players engaged and monetize your games. And we will help you start a career in the gaming industry.

Find out more