Sunday, October 8, 2017

The Last of Us : Technical Design for Stealth Mechanics


Consider a stealth based game where guards are patrolling with set paths. If an enemy detects the player, the enemy goes into a pursue state and pursues the player for some fixed period of time. Afterwards, they resume patrol.  If an enemy detects an incapacitated body (incapacitated by the player), he will enter a search state in which they search nearby for a specific time. Enemies aware of the player deal damage at a fixed rate when in proximity to the player.

Consider an architecture where a list of high level prioritized skills invoke lower level behaviors that interface with the locomotion controller:


Each skill decides internally whether it is on or off. Each skill also has an internal state machine. When a skill makes a decision it pushes a low level behavior onto a stack. All behaviors inherit from a BaseBehavior which the stack functions on. Similarly, there exists a BaseSkill behavior with functionality to push onto the stack etc.

Examples of behavior pseudo code is as follows :

1) Move To Destination - Receives parameters speed, destination and animation from invoking skill.

  • Invoke path finding algorithm. May contain a reference to a navmesh in order to compute path.
  • Read next node in path.
  • If node is reached, rotate to orient towards next point in path. 
  • Translate in forward vector direction at set speed.
  • Play Animation. May have a blend space between walk and run animations based on speed.

2) Attack - Receives attack type, attack direction, damage on success

  • Register for collision events
  • Play Animation
  • If collision registered, send damage message to PlayerController. PlayerController might manipulate the damage received based on state variables such as armor, defense state etc.
For skills to remain autonomous (i.e., not reference other skills) they will probably reference similar data. In order to ensure operations are not being duplicated across skills and to ensure skills are modular and decoupled, we could use a "shared blackboard".


The following skills may be required.

1) Patrol
  • To use this skill, the designer defines a set of patrol nodes and a patrol type (Looping, Ping-Pong etc)
  • To determine it's status, the skill reads timestamp player was last detected and time duration that the player was seen. continuously.
  • The blackboard itself updates these metrics based on the vision cone hitting the player.
2) Search
  • When a player is spotted for a threshold amount of time, search is enabled.
  • When enabled, raycasts are fired in a cone centered around the location the player was seen.
  • This returns a list of environment objects.
  • Based on the orientation of the NPC entity, a search point is generated for each object.
  • These points are represented in a graph.
  • A breadth first search is performed on the graph, with the point closest to last known player location being treated as origin.
  • Each node is visited one by one.

No comments:

Post a Comment