In the InVivo Corporation’s hospital you are not alone. Mutated
creatures hide inside the building and your goal is to avoid their deep
breathing at all costs.
During the preproduction phase, when everybody was throwing crazy ideas
about the game design, the monster behavior was one of the most fascinating
topics. How the monsters interact with the world and what action they could
perform at any given time, were the most essential issues we had to tackle.
Before setting up the main game, we created various prototype scenarios,
where the monster could patrol, investigate and chase the player. This led to
many hilarious situations, where the monster would walk through walls,
completely ignore the player presence or throw him over the test level edges!
In inVivo, the monsters are capable of not only seeing the player but
also hear his footsteps. Based on a viewing and a hearing distance, the monster
AI chases or
searches for the player’s position.
But how the monster changes its behavior? Using a finite state
machine (FSM) the AI chooses the appropriate action based on
player decisions and the environment. A finite state machine is composed by
states, events and a set of transitions. For example some of the monster states
are Patrolling, Investigating and Chasing. So at any given state, whenever an
event occurs, if there is a transition leading from the current state to a new
state corresponding to the event that occurred, the monster AI switches to the
new state.
Have a look at the AI state diagram:
Most of the time, the monsters will patrol in the dark corridors of the
InVivo’s hospital using a dynamic node system. But they will always be vigilant
about the player presence. So when the monster hears something it will switch
to investigation mode and if it spots the player it goes to chase mode.
In addition, the monster AI can interact with its surroundings and take
the appropriate action. For example the monsters can open doors to enter a room,
but also break them when they are in a hurry. This lead to a nerve wracking
experience for our programmers, when the monster AI dragged along the door, instead of
opening it with care!
The system is so flexible, so we can add more states to the FSM, keeping
in mind to add the right transitions between states. If you are not careful
this will lead to some strange visual bugs, where the monster opens a door,
while having a walking animation!
Visually all we have to do is to switch to the appropriate animation
clip, when we move between states. This is achieved using the Unity
Mechanim Animation System.
And that’s how the monster AI comes into play in
InVivo: Last Chance.