Skip to main content

Class ProximityGazer

Periodically scans for nearby GameObjects and commands a look-at gaze toward the closest valid target, simulating a pedestrian's natural attention response.

public class ProximityGazer : MonoBehaviour

Inheritance​

Remarks​

This component enables the behaviour of pedestrian looking at specific targets. Designers can configure detection radius and filter rules in the Inspector.

On each scan tick, a sphere overlap at ProximityRadius finds all nearby colliders, the configured filter rules (tag, layer mask, ScriptableTag) narrow those results to valid targets, and the closest one is passed to Single) on the receiver — held for GazeDuration seconds if set, or until the target leaves range.

Scanning runs on a configurable interval rather than every frame because Physics.OverlapSphere is relatively expensive; 100 ms (the default) provides responsive-enough gaze updates for a realistic pedestrian without frame-rate overhead. Multiple filter options (_PermissibleTag, _PermissibleLayerMask, _PermissibleScriptableTags) allow the same component to target vehicles in one scenario and other pedestrians in another without any code changes.