1

Research on the AI design in open world games

- What we have now

C.2 Desk Research

pg. 8

- Modern AI design- The AI design of Shenmue

pg. 9

C.3 Conclusion

pg. 10

- Future ImprovementAdd. Reading list

pg. 11

2Research on the AI design in open world games

PreludeIn preparation of the full-scale(post vertical slice) production of Baraka it was noted that there was adistinct lack of direction as it pertained to the AI system used in Baraka. As such a short but thoroughresearch is needed; as presented in this paper. This paper was meant as a short study of AI systemsin other, comparable games in order to give the information required to make informed decisionsabout the design of the AI system in Baraka.This system is preliminary. If, in a later stage of development, it is discovered that the system simplydoes not work, the system has to be changed and possibly completely overhauled.What we have nowWhen work was started on Baraka, it was thought up to essentially copy the system that AssassinsCreed used, simplifying it as much as possible. Simply put, agents (also called NPCs, civilians orpedestrians) walk on a network of nodes, one put on every street corner. Every node is then suppliedwith a list of other nodes that this node connects to (called neighbours). Every civilian walks fromnode to node, choosing a neighbour of the node if it is reached.Later on this system was expanded with a system that despawns agents if they walk too far awayfrom the player, and a system that re-uses these despawned NPCs (essentially by moving them closerto the player).NPCs popping into existence was also a problem. At first the problem was solved by checking if theNPC is in view (visible to the camera) when spawned, but this turned out to be way to heavy on theprocessor and as such could not be used. Later, a whole new system was made, using tangents andpure math (no actual mesh Line-of-Sigh/Raycast checks) which is in use now.When the player fires a gun and when someone dies, a bubble is spawned onto of that position.When an NPC walks into such a bubble, they will turn around 180 degrees and run for 100 metersbefore returning to the walk state. This often gives bad results such as NPCs running off cliffs or intothe river, or NPCs getting stuck in walls/running up against walls. There are more, smaller problemsbut this is the main problem of the current design.GoalThe goal of this research paper is first and foremost to find out whats best for Baraka. To do this, Imstudying other games in the genre, and investigating other games that sport a mass AI system ofsome kind. The result will hopefully be such, that it does not only provide answers to the questionsand problems presented above but also give new perspective on the design of the overall AI system,and possibly even give whole new ideas that otherwise wouldnt have been thought of, factors thatotherwise wouldnt have been considered. Criticism against open world games is often that theirworlds dont feel alive. Not long ago, it almost seemed like this living world buzzword was used sooften that actually having it in your game seemed like some sort of quest for replay value. Asecondary goal of this paper is to come closer to what having a living world actually entails beyondjust buzzwords.

3Research on the AI design in open world games

Chapter 1: Case study

The first part of the research consists of a case study. In this case study we investigate an already,finished product in an attempt to reverse engineer the systems used to fake illusion of walkingaround in a living city, that exists without the players interference. Keeping the limitations of lastgenerations hardware (Xbox 360 and equivalent) in mind, we know that actually doing this simulating an entire city at the same time is improbable.CaseThe game were looking at is Electronic Artists The Saboteur. This game waschosen because of the striking similarities between The Saboteur andBaraka. The style and age of the game (older algorithms are easier toreplicate) were also taken into account.The actual case study was done by observation: following civilians around asthey move through the streets, watching the reactions of civilians as theypass by street vendors, watching the civilian react to explosions andobserving when civilians spawn and when they despawn.ObservationIt appears there are three states the civilians find themselves in: the first, and most common, is thewalking state. It is when the civilian is walking down the street, moving from node to node, much likethe system Baraka has in place. This system appears to be common among open world games and assuch is a trope of sorts.The second state is the fleeing state. The civilian will flee when he hears an explosion or sees anyonecommitting violence. This does not have to be the player; soldiers will occasionally hit civilians too,when they bump into one another. Because of this, civilians sometimes run at you for apparently noreason. In the Saboteur, the civilians are supposedly on your side and as such do not react to theplayer pulling out a gun, but they do respond to the gun firing. When a fleeing civilian bumps into acivilian that is not fleeing, the civilian that is bumped into will flee as well.The third state is the action state. Sometimes, when civilians walk by street merchants, they will stop,look at the wares for some time, and walk off. Civilians also walk around only to stop to sit down on apar bench, or lean against a wall. Once they enter this state, they do not appear to leave it, unlessthey are put in a fleeing state.When civilians bump into each other, they, instead of playing a bumping animation and walking on,tend to stand there for a second and talk to each other, before walking on. The conversations areeither in French or English, the French conversations usually making little sense How are you?being replied to with Good Afternoon.. The German soldiers also talk to each other (in German),and to the player, and those conversations make little sense as well( Germans asking for papers at acheckpoint after just showing them and the gates having been opened).Not all civilians move around. Some, like the street merchants mentioned earlier, do not move ontheir own. This is comparable to civilians sitting on benches, with the difference being civilians neverseem to enter the state of tending to such a shop. They are spawned like that.

4Research on the AI design in open world games

A civilian browsing a street vendor (but never buying anything)

Civilians spawn some distance away from the player, never close to him. The distance between theplayer and a civilians that spawns is about 100-150 meters. Civilians that are further than 150 meterfrom the player despawn immediately. This distance is slightly larger for cars, presumably becausecars are larger. The spawn/despawn range seems to increase as the player looks down the scope of asniper rifle, with civilians popping in and disappearing as the player zooms in and out.

Left: normal, Right: Looking through scope

ParallelFor a more broad perspective on design tropes, I decided that it was a good idea to take a quick lookat other similar open world games as well. I did this with two games: Mafia 2 and Assassins Creed.Mafia 2:Mafia 2 appears to be using a system that is very similar to that of the Saboteur. Pedestrians walkfrom point to point, stop by street vendors (to buy newspapers, for example) and run away or cowerwhen the bullets start flying. Big Difference that the player can also buy from some of these vendors;the player can get his shoes shined, which does nothing in gameplay terms, but helps to increaseimmersion. The player can also enter many buildings, while in The Saboteur most buildings cant beentered. In these buildings, for example clothing stores (which is a planned feature for Baraka, too)or diners, civilians will never move. Even when shot at they will cower in place. They will spawn inthis state and will never leave it, so they are in that regard no like other normal civilians.

5Research on the AI design in open world games

Left: The player getting his shoes shined, Right: A pedestrian buying a newspaper

Assassins CreedAssassins Creed also uses a system that is very similar to that of The Saboteur. This is no surprise,keeping in mind that Barakas original system was based on that of Assassins Creed. Assassins Creedis also the oldest game in this list, and it shows. Out of all games, Assassins Creed seems to have theleast number of pedestrians walking the streets, having a very limited amount of interactions.

As you can see on this picture, there are only 6 real Pedestrian NPCs in the screen. The majority ofNPCs are actually forming a static crowd, which is not nearly as expensive as creating a movingcrowd. Keeping in mind that civilian #6 in the picture is a beggar (as described below), designed toharass the player, you can see that the civilians actually walk in straight lines, kind of like a trainwould. This refers back to the node based navigation network that the other two games also used,but in those games the NPCs walk near the lines, and not on it.

6Research on the AI design in open world games

In fact, this `large static crowd trick is used quite often. Because of this, the cost of the sheer amountof pedestrians (customizable in the options menu up to 105 NPCs, which is double what Baraka hasnow) is greatly reduced. These static NPCs will flee if provoked, and also count against the maximumNPC limit.

Left: Civilians standing near a salesperson, Right: Crowd standing near public speaker

This system is somewhat comparable, with the difference being most NPCs will never change statesand more NPCs group together, where in The Saboteur, at most, a single NPC would be browsing thewares of a street seller. In the Saboteur this NPC leaves after some time, but in Assassins Creed theydo not. Also note that in none of these three games you can actually buy from these streetmerchants.It should be noted that when you fire a gun, or kill an enemy, you provoke the pedestrians on thesidewalk. With that I am referring to a crowd of NPCs breaking up and fleeing in panic. In both Mafia2 and The Saboteur, it seems like the NPCs use real-time path finding to run away from you. InAssassins Creed, NPCs run away too but they still seem to use the same node network used for thewalk state, the exception being the node furthest from the player is chosen. In Assassins Creed,NPCs keep running until they despawn, while in the other games they stop running after some time.A feature that Assassins Creed does have that Mafia 2 and The Saboteur do not have, are civilianNPCs that directly engage with the player. In paper that sounds like a cool idea, but in reality I amtalking about beggars and madmen. This idea is novel though, and gets old pretty fast before actuallygetting annoying. The idea could potentially work but needs more thought.

7Research on the AI design in open world games

Chapter 2 - Desk Research

A desk research is a form of research that is done by looking at talks, discussions, data and opinionsof others. A list of the works referred to can be found at the end of this paper, in the Reading listaddendum.Modern AI designMost modern open world games use similar AI systems. Like the current system in Baraka, AI agentswalk from node to node. More advanced games, like Saints Row 4, use modular systems; all AIs usethe same base code but it is the specific code fragments that really specify the behaviour of theseagents. These fragments are highly reusable, such as specific code for aliens, police agents, gangmembers, et cetera. Other systems, like police road blocks, are generated on the fly.One interesting note is that Saints Row has asystem where Line-of-Sight checks/Raycastsare done on separate processing threads inorder to be able to use hundreds of them atthe same time. It is sad that Unity does notsupport this, seeing as Raycasts can only becalled from the main thread, but this couldpotentially be a huge gain for the CPUperformance for Baraka. Note that thesechecks are not done immediately; requests aremade, then later done by the backgroundthreads (which do not run synchronously withthe main thread), done in order of request.Example of a 20x increase in Line-of-Sight performance(15 vs. 0.75 seconds)

A popular modern method of handling mass AI is a system usually referred to as GOAP: GoalOriented Action Planning. With GOAP, every NPC has a list of goals, some finite (kill X, collect Y),some infinite (defend X, patrol between Y and Z). Because of this, every NPC has multiple things hecould be doing. In the background, a planner algorithm then calculates the fastest option ofcompleting each goal by giving every action a cost, such as walking (distance in meters) and attacking(distance from the target + set cost of attacking). The cost of attacking depends on the weaponcarried. This way, an NPC wielding dual swords has a lower cost for melee attacks and is much morelikely to do that.The cost of the fastest way of completing each goal is then compared, and the option with the lowestcost is chosen. The NPC will then act on that plan until the planner thinks of a plan with a lower costor until the plan is completed. Some goals can be prioritized, such as patrolling between two points,internally lowering the cost of that goal making it more likely for the AI to pursue it. The GameShadow of Mordor has expanded this even further: It uses GOAP, but also assigns specific roles to theAI. For Example: if a patrolling squad of Orks comes across a corpse, the entire squad will move overto the corpse, while one of them investigates, the others watch his back. If a single Ork comes acrossthe corpse he will investigate too, and if another comes across it he will watch the other Orks back.Any further Ork will then disregard the corpse immediately.These last few years, especially before GTA 5 came out, there has been much criticism about manyopen world games. These are usually levelled to open world games where there is no real gameplay8Research on the AI design in open world games

aside from the storyline and occasional run-ins with law enforcement. Games Like Mafia 2 are said tohave no real activities outside of those meant for making money and even then, the money cantbe spend on much of anything. Mafia 2 does have shops in the game but since half of these shops(clothing shops) are part of the game mechanics (changing appearance lowers wanted level) theseare a necessity and not a commodity. Even Middle Earth: Shadow of Mordor has been calledrepetitive over time. In Lonely planet: the solitude of open-world games when the story is over,an opinion piece published in The Guardian, writer Keith Stuart expresses his boredom with thegame, even though the games revolutionary Nemesis system was supposed to fix that.There is hope, however. Games like GTA are still being played an masse, and aside from that onewell-funded, hyped-up superfranchise there are many more Open World games that are being The AIdesign of ShenmueShenmue is a game originally developed for the Sega Dreamcast, by console manufacturer Segathemselves. While made during the late 90s, it came out in early 2000, having has a longdevelopment cycle and great investment cost making the game. Sega hoped for the game to becomea hit, a hit that never happened. Sega never made another console after the Dreamcast, and thefailure of Shenmue, among other things, caused Segas eventual withdrawal from the consolemarket. Because of this, Shenmue remained a somewhat obscure game until, in the late 00s, thegame was rediscovered by the YouTube community and became a cult classic of sorts.One of the reasons of its newfound popularity is because of its revolutionary AI system. Unlike othergames from the time period, in Shenmue you could walk around an entire city, talk to strangers andinteract with all sorts of little things; from mini-games to vending machines. It is touted by some asthe first open world game, though that claim is disputed. The first GTA games came way beforeShenmue, though not in 3D, and there were more games that came before GTA that could beconsidered open world.In Shenmue, NPCs live according to a daily schedule. In the morning, they will go to a conveniencestore to get food. Then, they will attempt to go to work, go home, eat, sleep, et cetera. This repeatsuntil the week is over, at which point the AI will change its schedule to one that is appropriate for theweekend. Players can talk to these AIs, and hold a though limited- dialog with them. The ideabehind this is that player is able to live in a virtual world, and the player was supposed to do just thisin the first part of the game. Later, the player had to investigate a murder by talking to NPCs usingthis conversation system. A conversation along the likes of Hey Mister, you wanna play basketballwith us? No, maybe later. Doesnt seem like much today, but at the time this was revolutionary.

9Research on the AI design in open world games

Chapter 3 ConclusionMany modern pre-GTA V suffered from the dead open world trope. These games, while having afull open world, these worlds felt dead and where rarely played after all missions have been played.To make the game and its city feel alive you need to have a good AI system which takes care ofrandom pedestrians walking the streets, going about their day.What the studied games do, is use a node-based system. Every street corner has a node and civilianswalk from node to node. Not every NPC uses this system. Some, like merchants stand still, and sellgoods to pedestrians, which may walk by to buy things. Because of this, especially in games releasedin the early PS3/Xbox 360 days, most NPCs walking around open world cities where of the latter kind,not moving around unless provoked to run away from the player. Actual interactive NPCs werentused as much.More modern game use the GOAP system, which assigns multiple tasks to an NPC and uses a mathcalculation to choose the most efficient one. This lends itself more to stealth/gunplay gameplayhowever, and is not as useful for pedestrian AI. It also strains the AI programming side of the gameeven more, and might not be viable because of that.In the past there have been games that have a much more in-depth AI system, simulating schedulesand running the AI trough a daily routine. While this lends itself well to the gameplay of HMG, I,again, strains development time, and Im not convinced theres much use in simulating this on everyNPC.Future improvementThe following changes/decisions have been made based on this research:-

The node-based system is kept. Up to 52 pedestrians roam the streets closest to the player.On high-end system this number may be increased via a .ini change.Aside from these roaming pedestrians we are adding static NPCs such as shopkeepers.Roaming pedestrians will occasionally walk by these merchants an buy from there. Playerscan also buy from street merchants to lower their risk rating.Soldiers will use a light GOAP system when in combat with the player. This system will alsobe used for stealth-based missions.A full daily schedule is simulated but only on a target NPC when the player is doing anassassinate or similar mission. The time of day never changes while in-game, so the scopeis this system is limited.