Tier 2
Series 104
104E: The Raycast
"A Raycast is an invisible laser used to "see" physics objects. An Engineer uses `Physics.Raycast` to check if the player is grounded, if a gun has a target, or if a door is open."
The Concept: Raycasting
Shooting a line through the physics world.
* **Origin:** Where it starts.
* **Direction:** Where it points.
* **HitInfo:** Data about what it hit (Name, Distance, Normal).
* **LayerMask:** Filtering what it can hit.
* **Origin:** Where it starts.
* **Direction:** Where it points.
* **HitInfo:** Data about what it hit (Name, Distance, Normal).
* **LayerMask:** Filtering what it can hit.
Red Flag Detected
The AI Trap: "The Infinite Laser"
You ask the AI: "Check if I am standing on the ground."
// AI-Generated Code: Unfiltered Scan
if (Physics.Raycast(transform.position, Vector3.down, out hit)) {
isGrounded = true;
}
// Audit Fail: This hits EVERYTHING. Including the player's own foot.
This is "Self-Detection." The raycast hits the player collider immediately and thinks the player is "grounded" in mid-air.
Elite Telemetry
Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."
- Small Batches Solving one problem at a time prevents logic drift.
- Modular Design Localizing the "blast radius" of AI changes.
- Tight Loops Rapid iteration with constant code review.
The Engineer's Correction
Corrective Protocol
// Corrected: Filtered Sight int layerMask = 1 << 6; // Layer 6 is Ground if (Physics.Raycast(pos, down, out hit, 1.0f, layerMask))...
Your Pilot Command
> Direct the AI to use the OnAudioFilterRead method for procedural sound generation.