Skip to main content

Class Sensor

Physics-based proximity sensor that fires a OnDetected event for every collider that enters its configurable arc- or cone-shaped detection volume.

public class Sensor : MonoBehaviour

Inheritance​

Remarks​

Unity's built-in OnTriggerStay drives detection rather than per-frame raycasting, because colliders for vehicles and pedestrians are large and irregular — a single raycast can miss a car that is slightly off-axis. The sphere collider defines the outer radius; angle and height checks in Vector3) refine that into the actual arc shape without requiring a custom physics shape.

Three modes cover the main use cases: Pie_2D for top-down gap-keeping (ignores height), Pie_3D for stop-line detection (needs height to avoid triggering from underground geometry), and Cone for VR gaze-direction sensors.

The ignore list filters own-vehicle colliders and known non-obstacles from triggering false positives. Rigidbody-based comparison is used rather than direct collider comparison because a vehicle may have multiple child colliders sharing one Rigidbody.

Fields​

OnDetected​

Event triggered when a collider is detected.

[Tooltip("Event triggered upon detection of a collider.")]
public UnityEvent<Collider> OnDetected

Field Value​

UnityEvent<Collider>

Properties​

DefaultSearchAngle​

Default detection angle set on Awake.

public float DefaultSearchAngle { get; }

Property Value​

float

DefaultSearchRadius​

Default detection radius set on Awake.

public float DefaultSearchRadius { get; }

Property Value​

float

SearchAngle​

Current detection angle in degrees.

public float SearchAngle { get; set; }

Property Value​

float

SearchRadius​

Current detection radius of the sensor.

public float SearchRadius { get; set; }

Property Value​

float

Methods​

IsPointInSenorView(Vector3)​

Determines whether the given point lies within the sensor's detection cone or arc.

public bool IsPointInSenorView(Vector3 collisionPoint)

Parameters​

NameTypeDescription
collisionPointVector3The point to evaluate.

Returns​

bool — True if the point is within the sensor's view.