๐Ÿง  Vision Field System for Unity

June 28, 2025 ยท View on GitHub

VisionFieldSystem โ€” is a modular and flexible field of view (FOV) system for Unity that combines visual cone rendering with target detection, taking obstacles into account. It supports various vision shapes and is fully configurable through the Inspector. Perfect for enemies, turrets, NPCs, guards, and any AI perception systems.

Watch the demo

Watch on YouTube

๐Ÿ“ฝ๏ธ Demo Preview

TypeMesh + Detector PairPreview
CircleVisionFieldMesh + TargetFieldDetector
ArrowVisionArrowMesh + TargetArrowDetector
Half EllipseVisionHalfEllipseMesh + TargetHalfEllipseDetector
TriangleVisionOffsetTriangleMesh + TargetOffsetTriangleDetector
SquareVisionSquareMesh + TargetSquareDetector
RhombusVisionRhombusMesh + TargetRhombusDetector

๐Ÿ“ฝ๏ธ Demo Videos

https://github.com/user-attachments/assets/c0864105-69f8-498b-9de5-39c403db2e54

https://github.com/user-attachments/assets/3f6d499e-c2e4-4b62-b511-3e272ae8206d

https://github.com/user-attachments/assets/8ce44c5d-a9ee-48d7-9dfa-58d729b61d30

โš™๏ธ Features

  • ๐Ÿงฉ Visual FOV using procedural mesh
  • ๐ŸŽฏ Raycast-based target detection with obstacle mask
  • ๐Ÿงช Debug Gizmos for ray tracing and hit visualization
  • ๐Ÿ› ๏ธ Fully customizable parameters (width, height, segments, tilt, offset)
  • ๐ŸŽฅ Runtime detection events: OnTargetDetected, OnTargetLost
  • ๐ŸŒ— RaycastOffset to avoid surface clipping
  • โ™ป๏ธ Clean modular architecture: easy to extend

๐Ÿงฐ How to Use

  1. Add a Vision Mesh component (e.g. VisionFieldMesh) to a GameObject.
  2. Attach the corresponding Target Detector (e.g. TargetFieldDetector).
  3. Set required masks and dimensions in the inspector.
  4. Enable Is Show Debug to see rays and hit points in the Scene.
  5. Subscribe to target events:
๐Ÿ—‚๏ธ Project Structure
bash
Assets/
โ””โ”€โ”€ Code/
    โ”œโ”€โ”€ Cameras/
    โ”œโ”€โ”€ Editors/
    โ”œโ”€โ”€ Enemies/
    โ”œโ”€โ”€ Infrastructure/
    โ”œโ”€โ”€ Levels/
    โ”œโ”€โ”€ Players/
    โ”œโ”€โ”€ UI/
    โ”œโ”€โ”€ Utilities/
    โ”œโ”€โ”€ Weapon/
    โ””โ”€โ”€ VisionCone/
        โ”œโ”€โ”€ Detectors/
        โ”œโ”€โ”€ Factory/
        โ”œโ”€โ”€ Provider/
        โ””โ”€โ”€ Visions/
_detector.OnTargetDetected += enemy => Debug.Log($"๐ŸŽฏ Seen: {enemy.name}");
_detector.OnTargetLost += enemy => Debug.Log($"๐Ÿ‘€ Lost: {enemy.name}");

โœ… Requirements

  • Unity 2021.3+
  • URP or Built-in RP
  • DOTween (optional, for demo animations)