Skip to main content

LOSSensor

Detects objects that are within line of sight. Subclass of Sensor.

Properties

InputSensor

A Sensor whose Signals will be tested for line of sight. See manual page.

PulseMode

One of EachFrame, FixedInterval or Manual.

PulseInterval

If PulseMode is set to FixedInterval, this is the time in seconds between each pulse.

BlocksLineOfSight

Layermask for which physics layers block line of sight rays.

IgnoreTriggerColliders

The line of sight will not be blocked by Trigger Colliders when this is true.

TestLOSTargetsOnly

If this is true the sensor will only attempt line of sight tests on objects that have a LOSTargets component. See manual.

NumberOfRays

The number of randomly generated raycast targets to test on each object. Does nothing if that object has a LOSTargets component.

MinimumVisibility

The ratio of unobstructed raycasts must exceed this value for the object to be detected by this sensor.

LimitDistance

Enables the Distance Limits feature when this is true.

MaxDistance

When LimitDistance is true an object must be within this distance for it to be detected.

VisibilityByDistance

A struct specifying how visibility is scaled as a function of distance. Choices are Step, Linear Decay or a Curve.

LimitViewAngle

Enables the Angle Limits feature when this is true.

MaxHorizAngle

When LimitViewAngle is true an object must be within this horizontal view angle to be detected.

VisibilityByHorizAngle

A struct specifying how visibility is scaled as a function of horizontal view angle. Choices are Step, Linear Decay or a Curve.

MaxVertAngle

When LimitViewAngle is true an object must be within this vertical view angle to be detected.

VisibilityByVertAngle

A struct specifying how visibility is scaled as a function of vertical view angle. Choices are Step, Linear Decay or a Curve.

Methods

GetResult(forObject)

ILOSResult GetResult(GameObject forObject)
Returns a data-object with details about the line of sight test for a given GameObject. The ILOSResult instances are cached by the sensor and reused each time it pulses. Don't hold onto this reference for long, it will be invalid after the next pulse.

GetAllResults()

List<ILOSResult> GetAllResults()
Returns a list of ILOSResult data-objects with line of sight results for all of the objects tested.

TestSignal(inputSignal)

ILOSResult TestSignal(Signal inputSignal)
Immediately test line of sight for a given signal and return the results. This gives you full control to test line of sight when ever you need. Just keep in mind that the ILOSResult is stored until the next Pulse and then returned to a cache.

var player = GameObject.FindWithTag("player");
var playerShape = new Bounds(new Vector3(0f, 1f, 0f), new Vector3(.3f, 2f, .3f));

var losSensor = GetComponent<LOSSensor>();
var losResult = losSensor.TestSignal(new Signal(player, 1f, playerShape));
if (losResult.IsVisible) {
Debug.Log("Player is detected with a visibility of " + losResult.Visibility);
}