Getting Started

What's Included:

  • Demo Scene

  • Sight Sense

  • Sound Sense

  • Sound Emitters

  • Basic Finite State Machine Template

  • Enemy Finite State Machine

How To Use

In order to get started attach either a SightSensor and/or SoundSensor MonoBehavior to your GameObject. Attaching Either Sensor will automatically attach a SensorController MonoBehavior that cannot be removed while Sensors are attached.

Sensor Controller

The SensorController.cs has two properties. You can easily enable or disable senses with the toggle or in code. SensorController runs on the LateUpdate gameloop. On Awake the SenseController finds any attached behaviors that implement SensorBase. It iterates over each sense and reports back the highest rated detection event.

Notifications can be enabled through the UI as well. This will invoke the below action anytime there is a detection update.

Detection Types

Noting that the highest rated detection event is TargetDetected

Sensors

Each Sensor Inherits from SensorBase. Adding New Sensors can be added by extending creating a new csharp script and inheriting from SensorBase.

Sight Sensor

The SightSensor has a Warning and Detection radius, angle, and layer masking for both detection and possible obstruction layers.

The Warning Radius must be larger than the Detection radius. To Disable the Warning radius altogether set the value to 0.

Likewise, the origin of the radius can be shifted by adding a GameObject reference into the Optional Line Of Sight property. Radiuses and detection angles can be viewed in Scene mode.

Anything within the viewing Angle that is not obstructed and withing the yellow circle will trigger a TargetDetectedCaution event. Anything within the red circle will trigger a TargetDetected event.

Sound Sensor

The SoundSensor has a Warning and Detection radius just like the SightSensor with the same use cases. Additionally There are property settings that dampen sounds if line of site is blocked by obstructions. Sound is detected in 3D space and the Sensor can be configured to listen to events by Tag or Layer. In order for the Sound Sensor to pick up sounds, sounds must be emitted by a SoundEmitter.

Emitters

New Emitters can be created by any csharp script that implements the EmitterBase

New Emitter Types should be added to the Emitter enum

Sound Emitters

Provided are two versions of SoundEmitters. SoundEmitter.cs and SoundEmitterWithAttachedAudioSource.cs. Both MonoBehaviors are functionally identical. SoundEmitterWithAttachedAudioSource.cs automatically attached an AudioSource to the GameObject and uses that AudioSource. SoundEmitter.cs Allows for AudioSources to be passed into it's methods.

Provided in the Demo Folder is a script that emits sounds on trigger without a sound clip

As shown in the example above, if you should to play a sound and emit a sound for the sound sensor to register, AudioSources must be played from the SoundEmitter exposed methods.

Basic Finite State Machine

In order to demonstrate how Senses could work in your project I'm also include a very basic implementation of a FSM. Please look at the FSM/Enemy folder for how to create your own StateMachineControllers and individual states.

Last updated