4.5 KiB
4.5 KiB
RaycastPro Integration Guide
This guide explains how to set up units with RaycastPro SightDetector integration for the Low Poly Battle Simulator.
Quick Setup Using the Helper Tool
-
Open the Unit Setup Helper
- In Unity, go to
Battle Sim > Unit Setup Helper - The helper window will open
- In Unity, go to
-
Configure Single Unit
- Drag your unit GameObject to "Target Unit" field
- Drag your UnitData ScriptableObject to "Unit Data" field
- Click "Setup Unit Components"
-
Configure Multiple Units
- Select multiple unit GameObjects in the Scene/Hierarchy
- Set the "Unit Data" field (optional, for units without UnitController)
- Click "Configure All Selected Units"
Manual Setup
Step 1: Create UnitData Assets
- Right-click in Project window
- Go to
Create > Battle Sim > Unit Data - Configure the settings:
- Detection Range: How far the unit can see
- Sight Angle X: Horizontal field of view (0-360°)
- Sight Angle Y: Vertical field of view (0-180°)
- Full Awareness Radius: Instant detection range
- Attack Range: Combat range
Step 2: Setup Unit GameObjects
Each unit needs these components:
- UnitController - Main AI logic
- SightDetector (RaycastPro) - Vision system
- UnitSightSystem - Bridge between the two
Step 3: Configure Components
UnitController:
- Assign the UnitData asset
- Set the team (Player/Enemy)
- Set unique unitId
UnitSightSystem:
- References are auto-assigned
- Configure layer masks:
- Enemy Layer Mask: Layers containing enemy units
- Ally Layer Mask: Layers containing friendly units
- Obstacle Layer Mask: Layers that block line of sight
Layer Setup Recommendations
Create these layers in your project:
- Player Units (Layer 8)
- Enemy Units (Layer 9)
- Obstacles (Layer 10)
- Terrain (Layer 11)
Configure Physics Layer Matrix
- Player Units should collide with: Terrain, Obstacles
- Enemy Units should collide with: Terrain, Obstacles
- Both unit types should NOT collide with each other (for movement)
UnitData Configuration Examples
Infantry Unit
Detection Range: 8
Attack Range: 2
Sight Angle X: 90
Sight Angle Y: 60
Full Awareness: 2
Move Speed: 3
Cavalry Unit
Detection Range: 12
Attack Range: 3
Sight Angle X: 120
Sight Angle Y: 90
Full Awareness: 4
Move Speed: 8
Can Charge: true
Archer Unit
Detection Range: 15
Attack Range: 8
Sight Angle X: 60
Sight Angle Y: 45
Full Awareness: 3
Move Speed: 2
Is Ranged: true
Max Ammo: 30
Performance Optimization
Pulse Detection
- Enable "Use Pulse Detection" in UnitData
- Set appropriate pulse interval (default 0.2s)
- Uses less CPU by not updating every frame
Target Limiting
- Enable "Limit Detected Targets"
- Set max targets (recommended: 5-10)
- Prevents performance issues with large armies
Layer Masks
- Use specific layers instead of "Everything"
- Only detect what you need to detect
- Configure proper obstacle layers for line-of-sight
Debugging
Visual Debug
- Enable "Show Debug Info" on UnitSightSystem
- Shows detection ranges and connections in Scene view
- Console logs for detection events
SightDetector Gizmos
- RaycastPro automatically shows field-of-view in Scene view
- Different colors for active/inactive states
- Shows detection radius and angles
Common Issues
Units Not Detecting Each Other
- Check layer masks are correct
- Verify UnitData detection range
- Ensure units are on proper layers
- Check if obstacles are blocking line of sight
Performance Issues
- Enable pulse detection
- Limit detected targets
- Reduce detection ranges
- Use fewer units or LOD system
Missing References
- Use the Unit Setup Helper tool
- Ensure all components are added
- Check UnitData is assigned
- Verify SightDetector configuration
Integration with Battle System
The sight system automatically integrates with:
- BattleManager: Coordinates all units
- BattleStrategy: Affects detection behavior
- Unit AI: Uses detection for targeting and movement
Units will react to detection based on their:
- Unit type (Infantry/Cavalry/Archer)
- Assigned strategy (Hold/Flank/Charge/etc.)
- Current state and health
Advanced Features
Custom Detection Reactions
Override ReactToEnemyDetection() in UnitController for custom behavior per unit type.
Dynamic Configuration
Call UpdateSightConfiguration() on UnitSightSystem to apply UnitData changes at runtime.
Manual Pulse Triggers
Call TriggerDetectionPulse() for manual update timing in special situations.