mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
- Added core LOS detection module (`js/systems/npc-los.js`) with functions for distance and angle checks, and debug visualization. - Integrated LOS checks into NPC manager (`js/systems/npc-manager.js`) to enhance lockpicking interruption logic based on player visibility. - Updated scenario configurations for NPCs to include LOS properties. - Created comprehensive documentation covering implementation details, configuration options, and testing procedures. - Enhanced debugging capabilities with console commands and visualization options. - Established performance metrics and future enhancement plans for server-side validation and obstacle detection.
5.8 KiB
5.8 KiB
LOS Visualization - Quick Reference
30-Second Quick Start
// 1. Open game in browser
// 2. Open console (F12)
// 3. Paste this:
window.enableLOS()
// You should now see green cones!
Visual Elements Explained
↑ Facing Direction
|
......|...... Range Circle (max detection distance)
./ .│. \.
/ . │ . \
/ . │ . \
/ . │ . \
/ === . │ . === \
/ / \ │ / \ \
/ / \ │ / \ \
/ / NPC \│/ \ \
/ / ● ● \ \ ← Angle Wedge (cone boundary)
\ \ │ / /
\ \ │ / /
\ \ ╱ ╲ / /
\ \ ╱ ╲ / /
\ ╲ ╱ ╲ ╱ /
\ ╲ ╱ ╲ ╱ /
\ ╲ ╱ ╲ ╱ /
\ ╱ ╱ /
╲/ ╱ ╱
╲╱╲ ╱╲╱ ╱
╲ ╱ ╲ ╱
╲╱ ╲╱
● = NPC Position Marker (bright circle)
█ = Filled Cone (player detection zone)
⟨ = Range Boundary Circle
↑ = Facing Direction Arrow
Console Commands
| Command | Effect |
|---|---|
window.enableLOS() |
Show green cones |
window.disableLOS() |
Hide cones |
window.npcManager.losVisualizationEnabled |
Check if enabled (true/false) |
window.npcManager.npcs.size |
Count of NPCs |
window.npcManager.losVisualizations.size |
Count of visible cones |
Color Guide
| Color | Meaning |
|---|---|
| Bright Green (100%) | NPC position marker and facing arrow |
| Medium Green (80%) | Cone outline/border |
| Light Green (60%) | NPC circle marker |
| Faint Green (20%) | Range circle boundary |
| Very Faint (10%) | Angle wedge lines |
Console Output Examples
✅ Everything Working
👁️ Enabling LOS visualization
🎯 Updating LOS visualizations for 2 NPCs
Processing "guard1" - has LOS config {range: 300, angle: 140}
🟢 Drawing LOS cone for NPC at (1200, 850), range: 300, angle: 140°
NPC facing: 0°
✅ LOS cone drawn at (1200, 850) with depth: -999
✅ Created visualization for "guard1"
✅ LOS visualization update complete: 2/2 visualized
❌ NPC Not Found
🔴 Cannot draw LOS cone - NPC position not found
{npcId: "guard1", hasSprite: false, hasX: true, hasPosition: false}
Solution: Verify NPC sprite is initialized before calling enableLOS()
⚠️ Missing LOS Config
Skip "guard1" - no LOS config or disabled
Solution: Add "los": {"enabled": true, "range": 300, "angle": 140} to NPC in scenario JSON
Testing Scenarios
Test 1: Basic Visualization
window.enableLOS()- Look for green cones on screen
- Verify they point toward NPC's facing direction
Test 2: Range Detection
- Move player closer/farther from NPC
- Watch for detection feedback in console
- Verify player detected inside cone, outside range
Test 3: Angle Detection
- Move player left/right relative to NPC
- Check if player is within cone angle boundaries
- Verify detection changes as you move
Test 4: Lockpicking Interruption
- Try to pick a lock near an NPC
- NPC should see you if in LOS
- Person-chat should start instead of lockpicking
- Check console for "NPC can see player" message
Debugging Checklist
- Green cones appear when
enableLOS()called - Cones disappear when
disableLOS()called - Arrow points in NPC's facing direction
- Range circle matches configured range
- Cone angle matches configured angle
- NPC marker at correct position
- Console shows success messages (🟢)
- Lockpicking interrupted when in NPC view
- Person-chat starts instead of minigame
Common Issues & Solutions
| Issue | Cause | Solution |
|---|---|---|
| No cones visible | Scene not ready | Wait 1 second after loading, then call enableLOS() |
| Cones invisible | Graphics behind terrain | Check console for rendering errors |
| Wrong cone position | NPC not initialized | Ensure NPC sprite exists before enabling |
| Detection not working | LOS config missing | Add los object to NPC in scenario JSON |
| Wrong facing direction | NPC facing not set | Set NPC direction or rotation property |
Configuration Template
Add to any NPC in scenario JSON:
"los": {
"enabled": true,
"range": 300, // pixels - how far they can see
"angle": 140, // degrees - cone width
"visualize": true // show debug cone
}
Performance Tips
- Each NPC cone: ~0.5ms per frame
- With 5 NPCs: ~2-3ms per frame (negligible)
- Visualization runs every frame when enabled
- Graphics depth set to -999 (behind everything)
URLs & Files
| Resource | Path |
|---|---|
| Test File | test-los-visualization.html |
| Debug Guide | docs/LOS_VISUALIZATION_DEBUG.md |
| System Docs | docs/LOS_SYSTEM_OVERVIEW.md |
| Source Code | js/systems/npc-los.js |
Keyboard Shortcuts
None defined yet, but you can add:
// In game loop or event listener:
if (key === 'L') window.enableLOS()
if (key === 'K') window.disableLOS()
Viewing Console
- Press F12 to open Developer Tools
- Click Console tab
- Type commands like
window.enableLOS() - Press Enter
Getting Help
Check these in order:
- Console output messages (look for 🔴 errors)
docs/LOS_VISUALIZATION_DEBUG.md(troubleshooting)docs/LOS_SYSTEM_OVERVIEW.md(technical details)- Verify scenario JSON has correct NPC config
- Check game loads successfully before enabling LOS