Sensing Component Documentation

 This documentation explains how to use the "Sensing Component" and its related configurations in Unity. The provided scripts can be utilized to develop AI characters with the ability to see and hear objects within the game.



SensingConfig.cs

SensingConfig.cs is a ScriptableObject-based configuration file. This file contains settings for the SensingComponent, enabling easy management and customization of sensor configurations within the game.








enableDebugging: Toggles debugging mode.
visionRadius: Radius of the vision cone.
visionLength: Length of the vision cone.
visionSegments: Number of segments to form the vision cone.
detectionLayer: Layer mask for detection.
sensingInterval: Time interval between sensing operations (in seconds).
maxHearingVolume: Maximum volume sensitivity for hearing.
enableHearing: Toggles hearing capability.
enableVision: Toggles vision capability.



To create a SensingConfig file, follow these steps in Unity:

    Go to Assets > Create > 34IBStudio > SensingComponent > SensingConfig





SetDetectionLayer:

    Sets a new detection layer mask.
    public void SetDetectionLayer(LayerMask newMax)

SetEnableHearing:

    Enables or disables the hearing capability.
    public void SetEnableHearing(bool newValue)

SetMaxHearingVolume:

    Sets the maximum volume sensitivity for hearing.
    public void SetMaxHearingVolume(float newValue)

DetectObjectsInCone:

    Detects objects within the specified vision cone and invokes the OnGameObjectSeen event if objects are detected.
    private void DetectObjectsInCone(Vector3 tip, Vector3 baseCenter, float radius, float length)

StartVisionDetection:

    Starts the vision detection coroutine.
    public void StartVisionDetection()

StopVisionDetection:

    Stops the vision detection coroutine.
    public void StopVisionDetection()

VisionRoutine:

    Coroutine that performs vision detection at specified intervals.
    private IEnumerator VisionRoutine()

SetInterval:

    Sets a new interval for sensing operations and updates the wait interval.
    public void SetInterval(float newInterval)

HandleGameObjectSeen and HandleNoiseHeard:

    Methods for handling the detection of game objects and heard noises, respectively.
    protected virtual void HandleGameObjectSeen(GameObject actor)
    protected virtual void HandleNoiseHeard(GameObject instigator, Vector3 location, float volume)





Usage

To use the updated SensingComponent:

  1. Create and Configure SensingConfig:

    • Go to Assets > Create > 34IBStudio > SensingComponent > SensingConfig.
    • Configure the settings such as visionRadius, visionLength, detectionLayer, etc.
  2. Add SensingComponent to AI Character:

    • Attach the SensingComponent script to the AI character GameObject.
    • Assign the SensingConfig file to the config field in the inspector.
  3. Implement Event Handling:

    • Use the OnGameObjectSeen and OnNoiseHeard events to define custom behaviors when objects are detected.












Comments

Popular posts from this blog

Documentation for Modular Female Character System

Sensing Component 2D Documentation