Stealth System
The stealth system contains a few different parts that allows the player to snap to walls, hide in shadows, and avoid enemies. It interfaces with the enemy behavior, visibility manager, and the event system in an elegant way.
Stealth System Case Study
This case study is about the different iterations that the stealth system went through over the course of the design process. All of the art is original, and I promise it is bad on purpose!
Player Behavior
Using the event system, it is easy to have an event trigger entering and leaving hiding whenever an enemy spots the player, or the player presses a button.
Getting the Closest Wall
The first part of the stealth system, is getting the closest wall. This is only done when the player wants to enter stealth, or is trying to move from one wall to another. It uses a physics overlap sphere to detect any mesh on the specified layer mask, and adds it to a buffer to reduce physics calculations. It then does some simple math to determine which wall is closest to the source location, currently this is only the next position the player will be at.
Visibility
The visibility of the player is actually a feature of the enemies as a modifier to their vision range, instead of a property of the player. This way, I can make sure to only draw a raycast from the enemy to where the player is, if the distance between them is less than the vision range. The vision is modified by the light level and if the player is crouched / in stealth / sprinting. This was achieved by using a sampler to get the light level from the light probes baked into the lighting, and the event system to know what state the player is in.