AI
There are many unique AI agents in MODERN MEDICINE. The below section is a summary of what they are and what they do. The section after that describes core systems and gives implementation examples.
MONSTERS
LARRY
Larry is the flagship monster - an experiment on the hospital’s janitor gone wrong. He intercepts players in the halls every time the lobby completes a major milestone of the quest line, and if a player gets too close they are dealt an extreme amount of damage. To add to the challenge, each additional time he spawns he is given increased speed. He utilizes the player region module to locate his target and the A* module combined with the level node graph to pathfind to his target.
Larry’s design consists of several key points:
- Each step Larry takes sends the booming sound of his weight reverberating through the hallways. This is the first warning sign to the player that he is near.
- The closer Larry is to the player, the more his footsteps shake the player’s screen.
- Larry emits a terrifying noise which gets louder as he nears a player.
- With each footstep, Larry spawns a ring of fire around his body, adding to the spectacle while also denoting his attack range to the player.
JOHNNY
Johnny is a radiation monster spawned from additional inhumane experiments conducted in the hospital. He resides in the medicine floor, randomly navigating from one end of the hallways to another. When the player is close, Johnny emits a geiger counter noise as well as immense screen shake. As he flys through the halls he opens doors to the patient rooms on either side of him, making the experience of players hiding in these rooms that much more immersive.
Because the layout of the medicine floor is generated using prefabricated assets and he does not chase players, there is no need to use A* pathing for his navigation. Instead, a series of nodes are placed in each sub-layout that define a path from an out-of-bounds part of the hallway to the main, unchanging “L” hallway. For each monster cycle, a random out of bounds start point is chosen, the monster follows that point’s path to the main hallway, then it randomly chooses another path to an out of bounds region.
DR. THOMPSON
Dr. Thompson is the main villain of the hospital. The player only encounters his projected forms in the Operating Room, where he is seen standing frozen over the player’s character immobilized on an operating table. If the player looks at him for too long, his head will suddenly animate and stare at the player. As soon as line of sight is broken between the player and Dr. T., the player is transported onto the operating table for a POV experience of the doctor operating on them.
For best responsiveness, Dr. Thompson’s vision system is client sided. There are 3 checks that must pass for a player to be attacked by the monster:
- The player must be within the proper distance
- The monster must exist within the player’s viewport
- A raycast from the monster’s head must hit the player. Note: collision groups are used to allow for raycasts through transparent objects in this scenario.
If every check passes, then the player is looking at Dr. Thompson. After a short but random amount of time, Dr. Thompson will activate, staring down the player. Once line of sight is broken, he attacks.
ROACHES
Roaches wander the hallways. When hungry, roaches will fly onto the player’s face and will attack until they are swatted away.
WANDERING FACES
Wandering Faces are monsters that slowly float along the hallways. Whether they try to navigate to a player or wander randomly is left to chance. When the player looks at a wandering face, they start to get a tunnel vision effect. If the stare for too long, the wandering face will draw the player into it, dealing damage.
To make the hallways feel dense and to save on resources, there are only ever a small number of wandering faces in the world at any given time. Once a face is far enough away from all players, it respawns in a location closer to the action.
HUNTER
The hunter is a monster that was added to solve a critical issue we came across while playtesting: players in random lobbies don’t stick together. We developed the core quest system under the assumption that as soon as one player finds the room they need to go to, all the players would be able to easily and quickly join them. This held true for private playtests with friends and family, but as soon as we tested with random people who didn’t know each we quickly discovered this would not always be the case. Thus the hunter was created to deal with stragglers and keep the game progressing smoothly.
Hunters spawning in is signified by every direction panel illuminating simultaneously. Each player is hunted by a unique hunter which is only visible to them (but still controlled by the server). The hunter will follow and observe the player at a distance. After the player has remained in its line of sight for long enough, its body will turn neon orange - signifying that it is preparing to attack. When it does attack, it deals a moderate amount of damage and teleports the player to the destination room for the current quest. The player can delay the hunter’s attack by breaking line of sight or hopping into various rooms along the way. If they player stays in a room for too long, however, a warning effect will play and after some time the hunter will still attack.
UNSEEN ONES (ANGELS)
Unseen Ones are the final monster encountered in the game and my personal favorite. They are heavily inspired by the Weeping Angels from Dr. Who. During the game’s finale, the hallways completely regenerate and feature only one biome: the experimentation wing. This is where the unseen ones are found. These monsters silently stalk the player and move incredibly quickly when out of sight. However, when the player has any of the monsters within their line of sight, they feeze mid animation and appear as a statue.
On their own they are not that challenging to get past if you are aware of them, but the true difficulty comes closer to the end of the game. As the player progresses through the experimentation challenges, more and more monsters spawn in the hallways, including the Wandering Faces. This creates a unique synergy because the Wandering Faces will attack if you look at them for too long, and the Unseen Ones will attack if you look away. So when the hallways have both, it creates a stressful and fun challenge.
Unseen Ones’ movement logic works by checking two primary things:
- Is there a valid raycast between the player and the monster
- Is the player looking at the monster
To simplify communication, these movement checks are performed on the server. Checking the raycast simply checks if there are any objects between the player and the monster. Other agents do not count as valid objects for this raycast and are filtered out. Checking if the player is looking at the monster takes the vector between the agent and the player, then performs the dot product to get the angle between that vector and the player’s look vector
local dVec = agentHead.Position - viewerHead.Position
--Positive means the angle between the two vectors is less than abs(90). 0 is a right angle, negative is not visible
local inFov = dVec:Dot(viewerHead.CFrame.LookVector) > 0
SYSTEMS
AI agents all share several core systems. Monsters that navigate the hallways reuse the A* module found in other parts of the code. Other monsters that spawn inside rooms utilize a more simplistic node based navigation system. All 3D monsters utilize the same animation module, which allows both the client and the server to control an agent’s animations.
For more complicated agents, behavior trees are necessary to map out their logic. I utilize the BTreesV5 plugin to streamline my implementation.