Skip to content

A Unity library providing various 2D and 3D sensors to detect objects within the game environment

License

Notifications You must be signed in to change notification settings

DerKekser/unity-sensors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity - Sensors

Sensors is a Unity library providing various 2D and 3D sensors to detect objects within the game environment. These sensors can be particularly useful for AI development.

Contents

Sensor Types

Each sensor type is available in both 2D and 3D and operates similarly

General Sensor Properties

Property Type Description
Auto Update Sensor bool Enables automatic sensor updates.
Ignore GameObject[] Ignores specified objects.
Check Visibility bool Checks if detected objects are visible.
Scan Layer LayerMask Defines the layer of detectable objects.
Obstruction Layer LayerMask Specifies the layer obstructing visibility checks.
Scan Rays int Number of rays used for visibility checks.
Visibility float (0-1) Percentage of rays needed to detect an object for visibility.
OnEnter UnityEvent(GameObject) Triggered when an object enters the sensor's range.
OnStay UnityEvent(GameObject) Triggered when an object stays within the sensor's range.
OnExit UnityEvent(GameObject) Triggered when an object exits the sensor's range.

Access the sensor data

RaySensor sensor = GetComponent<RaySensor>();
GameObject[] detectedObjects = sensor.DetectedObjects;

Manual Update

RaySensor sensor = GetComponent<RaySensor>();
sensor.SensorUpdate();

RaySensor

RaySensor RaySensor2D

Uses a single ray to detect objects.

Property Type Description
Distance Float Range of the sensor.

RaySensor

RangeSensor

RangeSensor RangeSensor2D

Uses a sphere to detect objects.

Property Type Description
Range Float Range of the sensor.

RangeSensor

ViewSensor

ViewSensor ViewSensor2D

Uses a cone to detect objects.

Property Type Description
Distance Float Range of the sensor.
Angle Float Angle of the sensor.

ViewSensor

TriggerSensor

TriggerSensor TriggerSensor2D

Uses a trigger collider to detect objects. The trigger collider component must be attached to the same GameObject as the sensor.

TriggerSensor

Install

Install via Unity Package

Download the latest release and import the package into your Unity project.

Install via git URL

https://github.com/DerKekser/unity-sensors.git?path=Assets/Kekser/Sensors

Package Manager

License

This library is under the MIT License.