Even though there are multiple ways to detect characters and objects, the ultimate goal is to determine whether an object A is aware of another B or not.
The Awareness is a value that aims to simplify how an agent communicates and reacts with other game objects.
Example of Awareness
Let's say we have an enemy agent that can detect the player using Sight, Hearing and Smell. It would be very difficult to react when the enemy detects the player if we didn't have the Awareness meter, because we would need to control what happens when any of the possible combination of all three sensors detect or not the player.
For example, what would happen if the enemy sees the player? What happens if the enemy can see the player, but also hear it? What if it hears it but can't see it? Any of these permutations increase the complexity of building a robust detection system.
In this module the Awareness is a unique value stored in the Perception component that tracks how aware the agent is of each tracked object. This value ranges between 0 (not aware at all) and 1 (fully aware of the target).
The Perception component has a list of Sensors that feed the awareness value independently from each other. By doing so, one can create an enemy AI that reacts according to how aware it is of the player, instead of relying on information from each of the sensors.
Awareness as Stages
The Awareness can be read as a value between 0 and 1, but in some cases, it may be easier to give a name to awareness ranges. The Perception module provides 4 ranges:
- None: The Awareness value is between 0 and 0.05
- Suspicious: The Awareness value is between 0.05 and 0.5
- Alert: The Awareness value is between 0.5 and 0.95
- Aware: The Awareness value is between 0.95 and 1
The Perception component does not automatically track all scene objects. The user can define which objects are tracked (or untracked) at any moment using the Track Awareness and Untrack Awareness instructions respectively.
Tracking the Player
The most common use-case is for an enemy to track the Player. To do so, simply add a Trigger with the On Start event with the following Track Awareness instruction:
Once an object is being tracked it will appear at the bottom of the Perception component during play-mode along with a progress bar. This is useful for debugging how aware the component is of the tracked game object.
One a Perception component tracks a game object there are multiple ways to increase its Awareness. The easiest one is using the Increase Awareness instruction, which apart from incrementing the awareness, it also allows to cap its increment up to a certain maximum.
The Max Level field allows to determine a maximum level in which the Awareness can increase. This is useful, for example, when the player breaks a crystal glass.
In this case, the enemy will increase its awareness, but even if the player breaks more glasses, the enemy will never reach the point of highest awareness, until it has a clear line of sight.
The other way to increase Awareness is using the Sensors, where each one works differently.
A Perception component requires a rather frequent stream of stimulus in order to keep its awareness on tracked game objects. The Perception component has the following fields that helps control how it behaves when stimulus stop being received:
- Forget Speed: The speed at which Awareness decreases over time.
- Forget Delay: The minimum amount of seconds it takes without receiving any stimulus before the Awareness starts decreasing.
The exception is when the Perception reaches the Aware stage. In this case, if the Can Forget field is disabled, the Perception will never decrease its Awareness of the game object.
However if the Can Forget field is ticked, instead of the Forget Delay it will require the amount of seconds specified in the Duration field in order to start decreasing the Awareness.
Why Aware stage is different
The Aware stage can have a different amount of seconds in order to forget the specified game object because in most games, an enemy being aware of the Player means entering combat mode.
When characters are in combat, the player is likely to seek cover, and enemies could easily lose sight of the player. To avoid enemies being too forgetful it's a good practice to add a high amount of seconds before enemies start forgetting the player was seen.
Perceptions can also send Awareness information to other Perception components in order to make them appear like they work as a team.
Inform when the Player is spotted
A common practice of an enemy spotting the player is to inform nearby guards that the player has been found, raising their Awareness. This can be easily done using the Relay Awareness instruction, which transfers all Awareness knowledge from one Perception component to another, without the second one losing any knowledge.