Using the Sound Detector System - Black-Horizon-Studios/Emerald-AI GitHub Wiki

Using the Sound Detector System

Emerald AI's Sound Detector is an external component that gives AI the ability to hear unseen targets by tracking their noise levels. When player targets enter an AI's Detection Radius, their movement and velocity are tracked to simulate noise levels. As a target is moving, their sound level is stored and incrementally raises any nearby AI's Threat Amount and when all targets are slow enough, it will lower any nearby AI's Threat Amount. Depending on the Threat Amount an AI reaches, it will trigger a list of modular user set reactions.

Table of Contents

Sound Detector System

The Sound Detector System is what allows AI the ability to hear sounds and detect noises made by Attract Modifiers. AI need to have a Sound Detector component applied to it in order to use the sound detector features. This section explains the editors and functionalities of this component. For a detailed guide on adding a Sound Detector component to your AI, please see the section Adding the Sound Detector System to an AI.

The sound detector system and its settings are split into 2 sections (Sound Detection Info and Sound Detection Settings) with each of the 3 Threat Levels (Unaware, Suspicious, and Aware) having their own settings.

Info

The Sound Detector Info gives real-time information on the AI's Current Threat Level and its Currently Threat Amount.

Settings

The Sound Detector Settings gives users control over how often sound detection calculations are made, the minimum needed velocity, the how quickly noise level will raise, and how quickly the noise level will fall. There's also an option to control how often an AI can detect Attract Modifiers.

Threat Levels

There are 3 threat levels with each being triggered when the Current Threat Amount value threshold is met. When a target is within an AI's Detection Radius, it will automatically be added to the AI's Sound Detector so its noise level can be tracked. Multiple player targets can be tracked at once and each target's noise data is stored. All targets will contribute to the AI's Current Threat Amount. When an AI's Threat Level thresholds is met, it will invoke the reaction for that Threat Level.

Threat Level Description
Unaware Unaware will only be triggered after an AI has become Suspicious or Aware. This can happen after a target has been lost or is too quite to be detected. This should be used for resetting an AI back to its original settings, given they've been modified with a Reaction Object.
Suspicious Suspicious will only be triggered once and after an AI has reached a Suspicious Threat Level. It will not trigger again until after the AI has engaged with a target or if it has reached the Unaware Threat Level.
Aware Aware will only be triggered once and after an AI has reached an Aware Threat Level. It will not trigger again until after the AI has engaged with a target or if it has reached the Unaware Threat Level.

Reaction Objects

Reaction Objects are a list of modular reactions an AI will make when certain sound related mechanics happen, such as hearing a collision noise or reaching different Threat Levels. These reaction are always followed from top to bottom with various settings for controlling delays and conditions allowing for further unique and believable functionality.

Creating a Reaction Object

A Reaction Object can be created by right clicking in the Project area and going to Create>Emerald AI>Create>Reaction Object

All Current Reaction Types (more will be added with future updates)

Example Reaction Objects

Since this is a pretty in-depth and complex system, it will be explained in segments from a very simple reaction to more complex ones. Assume the following Reaction Object is called when an AI reaches the Suspicious Threat Level. (These examples are included with the 3.2 update)

Very Simple

Display a debug message that reads "What was that?!" to the Unity Console.

Simple

Display a debug message that reads "What was that?!" to the Unity Console, move to the loudest detected target, and then wait 3 seconds.

Intermediate

Display a debug message that reads "What was that?!" to the Unity Console, play an emote animation with an ID of 1, delay the next reaction by 1 second, move to the loudest detected target, and then wait 3 seconds.

Advanced

Display a debug message that reads "What was that?!" to the Unity Console, play an emote animation with an ID of 1, delay the next reaction by 1 second, generate 2 waypoints within a radius of 5 units of loudest detected target waiting 2 seconds in between each waypoint, wait for the AI to finish reaching all waypoints, and then display a debug message that reads "Hmm...guess I'm hearing things..." to the Unity Console.

Complex

Display a debug message that reads "What was that?!" to the Unity Console, have the AI enter its combat state (allowing it to equip its weapon and use its combat animations), delay the next reaction by 1 second, set it to use its run animations, generate 2 waypoints within a radius of 5 units of loudest detected target waiting 2 seconds in between each waypoint, wait for the AI to finish reaching all waypoints, exit its combat state (allowing it to unequip its weapon and use its non-combat animations), reset all other settings back to their defaults, and then display a debug message that reads "Hmm...guess I'm hearing things..." to the Unity Console.

Adding the Sound Detector System to an AI

Ensure your AI is fully setup through the Emerald AI Setup Manager and that it is fully working with all needed animations and settings. If you have not done this yet, please see the Setting up an AI section.

Step 1 - Adding the Emerald AI Sound Detector component

Find the SoundDetector script by searching for SoundDetector within the Project tab. Drag and drop it at the top of your AI.

Step 2 - Assigning Reaction Objects

After adding a new Sound Detector component, each of the reaction slots will be blank. These reaction slots control what reactions the AI takes when each Threat Level is met. A Reaction Object holds a list of reactions that the AI will follow in order.

Assign a Reaction Object to each slot. While starting off and familiarizing yourself with the Sound Detector System, it is recommend to use the included example Reaction Objects. Assign the Unaware reaction object, to the Unaware reaction slot, the Suspicious reaction object, to the Suspicious reaction slot, and the Aware reaction object, to the Aware reaction slot.

Step 3 - Adjusting the Sound Detector Settings

After the AI has a Sound Detector component and Reaction Objects assigned for each Threat Level, it has sound detector capabilities. Users can fine tune the Sound Detector Settings to suit their needs.

Note: The higher the Check Increment, the more accurate the sound detector process will be. The Min Velocity Threshold controls the minimum velocity will be needed to increase an AI's Threat Level and Current Detected Noise Level (CDNL). When this happens, the AI's CDNL will be increased by the Attention Rate. If all detect targets' velocity is below the Min Velocity Threshold, it will decrease the CDNL by the Attention Falloff.

An AI's levels update in real-time which can be seen in the Info within the editor. This can further help users finetune their Sound Detector Settings.

Using an Attract Modifier

The Attract Modifier will attract AI that are within range and invoke the 'Attract Reaction'. The object the Attract Modifier is attached to will be the source of attraction. This system is intended to extend the functionality of the Sound Detector component by allowing certain objects, collisions, and custom calls to attract nearby AI.

Step 1 - Adding an Attract Modifier to a Gameobject

Find the AttractModifier script by searching for AttractModifier within the Project tab. Drag and drop it at the top of your AI.

Step 2 - Specifying the Emerald AI Layers

After you have added an AttractModifier to your object, you will need to specify your Emerald AI Layer. When the AttractModifier is triggered, it will send information to all detected AI with this layer that are in range.

Step 3 - Assigning a Reaction Object

Next, you will need to assign a Reaction Object. For this tutorial, just using one of the included Move To Attract Source (Attract Modifier) example.

Step 4 - Adjusting the Attract Modifier Settings

Adjust the Attract Modifier settings as needed. There are options to have the Attract Modifier triggered OnStart, OnTrigger, OnCollision, and with a custom call. Ensure you have a rigidbody component on your game object if your Attract Modifier will be using OnTrigger or OnCollision.