Overview
The SightRange system allows you to create enemies or other objects that react when a target enters their field of vision.
You can also configure settings such as “enemies cannot detect targets behind walls.”
This system works by combining two components:
- The SightRange node, which defines an object’s field of vision.
- The TargetSighted condition, which checks whether a target has entered that vision range.
Technical Overview
From the origin of the SightRange node, raycasts are emitted according to the shape of its polygon.
The system determines detection by checking whether these raycasts intersect with the target object’s [CollisionShape2D].
About the SightRange Node
The SightRange system consists of two parts:
- The SightRange node, which defines detection behavior.
- The CollisionPolygon2D node, which defines the shape of the vision area.
SightRange Node Settings
- Sight Shape
You can select a preset shape for the field of vision — circular, rectangular, or capsule-shaped.
When you press the “Create” button, the child node’s CollisionPolygon2D shape will be overwritten accordingly. - Iteration (iteration)
Determines how frequently the vision check (raycast) is performed.
The default value of 5 is generally sufficient.
Higher values yield more precise detection, while lower values reduce processing load. - Ignore Walls (detect_behind_cover)
Allows you to ignore wall collisions from other objects.
You can configure detailed behavior for this in the Obstacle Layer setting described below. - Rotate with Facing Direction (follow_direction)
Makes the field of vision rotate according to the object’s facing direction. - Obstacle Layer (obstacle_layer)
Specifies which collision layer counts as an obstacle that blocks vision.
This depends on each object’s CollisionShape2D and tile collision settings.
Other Important Properties of the SightRange Node
- CollisionObject2D > Collision
You can configure the collision layer and mask of the vision itself.
This allows detailed control over which objects can be detected or ignored, just like attack or hit detection settings.
CollisionPolygon2D
This is Godot’s standard node for creating polygons.
You can freely adjust vertex count and positions, allowing not only size changes but also custom-shaped vision fields — such as fan-shaped or complex areas.
The Condition “TargetSighted”
This condition is applied to the detecting object.
When a specific group or designated object enters its field of vision, the condition returns TRUE, triggering a state transition.
“TargetSighted” Condition Settings
- Target SightRange
Specifies which SightRange node to use for detection. - Target All Layers
When enabled, all collision layers are checked, regardless of the SightRange’s own settings. - Target Type
Allows you to choose whether to detect a Group or a specific Object.