Skip to main content

Tall-Grass Stealth Trigger Box & Guard Vision Cone Lab

Guards walking right past knee-high grass is not bad AI — it is an explicit Stealth Trigger Box overriding head/weapon visibility. Play this 60fps Canvas sandbox to toggle X-ray Trigger Box wireframes, Coyote exit grace, proximity bump reveal, and gradual suspicion gauges.

LIVE ENGINE DEBUGGER
toeInTriggerBox
true
stealthFlag
ON (隐身)
Cones Bypassed
0
Max Suspicion
0%

BINARY BOX VS 3A STEALTH AUDIT

🌿 Binary Box0ms snap
🦅 Assassin352ms + bump
🎯 AAA Gradual1088ms reaction window
01

Volume-first Trigger Box checks foot/toe bounds so protruding heads & weapons never cause unfair spots

02

1-click comparison: Binary 0ms edge snap vs 360ms Coyote exit grace & proximity bump reveal

03

Guard vision cones visibly bypass active Trigger Boxes (?) and snap to full alert (!) on break

04

Drag hero with mouse/touch or WASD + C crouch to audit stealth readability live at 60fps

Installable Agent Skill · Free

Drop straight into Claude Code, Cursor, or Codex

Paste into your AI agent chat
Read https://gameskill.dev/labs/stealth-grass-vision/skill.md and apply this skill to my game
Go Deeper · Companion GameSkill Pro Kit

Companion pack "Roguelike Combat & Boss Kit" ships runnable JS/TS + Godot 4 (.gd) + Unity (.cs) source code — unlock all 12 multi-engine Pro packs + 84 commercial WAV SFX + 8 2D VFX shaders from $8.25/mo ($99/yr, save 36%) or $12.9/mo.

Full SKILL.md Specification & Verification Checklist

Tall-Grass Trigger Box & Guard Vision Cone Stealth (EP31)

Core Problem: Why Real 3D Mesh Occlusion Breaks Stealth Games (And Why Pure Binary Boxes Feel Janky)

  • Trap A — Pure Line-of-Sight Raycast Only: If guards raycast against your character's head or weapon sticking out above knee-high grass, players get spotted constantly despite feeling visually hidden — stealth becomes frustrating and unreadable.
  • Trap B — Raw Binary Trigger Box Only: Setting player.hidden = isToeInsideTriggerBox makes stealth readable (used in Honor of Kings, Assassin's Creed bushes, and classic arena games), but without an edge grace window or proximity bump check, stepping 1 pixel past the wireframe triggers a 0ms telepathic full-room alert while guards literally walking through your face stay blind.

5 Production Rules (Ship-Ready Stealth Architecture)

  1. Rule 01 — Volume-First Stealth Trigger Box (Never Raycast Individual Grass Blades):
    • Place an explicit AABB / Capsule TriggerBox under every stealth bush. Test the player's foot/toe collider against the Trigger Box so visual props (swords, capes, helmet crests) never cause unfair false positives.
  2. Rule 02 — Post-Exit Coyote Stealth Grace (320–420ms):
    • When the player's toe clips 1px outside the Trigger Box edge, keep stealthActive = true for a 360ms grace timer before breaking stealth — preventing accidental "half-step instant alert" frustration.
  3. Rule 03 — Close-Range Proximity Bump Reveal (40–48px):
    • Add an inner body-collision radius around guards: even inside tall grass, if a guard walks literally face-to-face into the player's body, break stealth cleanly so AI feels believable.
  4. Rule 04 — Gradual Suspicion Gauge (0% -> 100%) Instead of 0ms Telepathy:
    • Fill a visible ? -> ?? -> ! suspicion meter scaled by distance (closenessMult) instead of instant frame-0 alert so players always have a fair window to duck back into cover.
  5. Rule 05 — Always Provide a Debug Wireframe Overlay:
    • Render the Trigger Box bounds (green = active, red = inactive) and guard FOV cones in dev builds so level designers can verify bush footprints match artwork.

Verification Checklist

  • Toe 2px inside Trigger Box keeps player hidden under direct guard FOV sweeps (exposed head/weapon ignored).
  • Stepping outside the Trigger Box under Binary mode snaps alert immediately (0ms), while AAA mode grants a >= 300ms reaction window.
  • Close-range bump (<= proximityRevealPx) overrides grass stealth cleanly in Assassin / AAA presets.
  • Disabling Trigger Box (raw-los) immediately exposes the player to sweeping guards, proving why Trigger Boxes are required.

ENGINEERING BREAKDOWN & BENCHMARK

Why Naive AI Implementations Fail (Measured Benchmark)

Raycasting against individual grass meshes causes players to get spotted whenever a helmet plume or sword tip peeks above waist-high foliage. Production stealth systems decouple visuals from logic using a ground foot-collider Trigger Box, a 320–420ms exit coyote grace window, a close-range bump radius, and a distance-weighted suspicion gauge.

Preset audit: Binary Trigger Box = 0ms instant snap on step-out vs Assassin = 352ms coyote grace + proximity bump vs AAA = 1,088ms fair reaction window.

PRODUCTION CODE · GODOT 4 · UNITY C# · TYPESCRIPT

Reference Implementation in Godot 4, Unity C#, and TypeScript

Godot 4 (GDScript)

stealth_grass_zone.gd
extends Node2D

@export var exit_coyote_sec: float = 0.36
@export var bump_reveal_px: float = 44.0

var in_grass_box: bool = false
var exit_grace_timer: float = 0.0
var is_crouching: bool = true

func is_stealth_hidden(guard_pos: Vector2, player_pos: Vector2) -> bool:
	# Close-range body bump always breaks tall-grass stealth
	if guard_pos.distance_to(player_pos) <= bump_reveal_px:
		return false
	if not is_crouching:
		return false
	return in_grass_box or exit_grace_timer > 0.0

func _physics_process(delta: float) -> void:
	if in_grass_box:
		exit_grace_timer = exit_coyote_sec
	else:
		exit_grace_timer = maxf(0.0, exit_grace_timer - delta)

Unity (C#)

StealthTriggerZone.cs
using UnityEngine;

public class StealthTriggerZone : MonoBehaviour
{
    [SerializeField] private float exitGraceSec = 0.36f;
    [SerializeField] private float proximityRevealDist = 1.4f;

    private bool _footInGrass;
    private float _graceTimer;
    public bool IsCrouching = true;

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("StealthGrass")) _footInGrass = true;
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("StealthGrass")) _footInGrass = false;
    }

    private void Update()
    {
        _graceTimer = _footInGrass ? exitGraceSec : Mathf.Max(0f, _graceTimer - Time.deltaTime);
    }

    public bool IsHiddenFrom(Vector2 guardPos)
    {
        if (Vector2.Distance(guardPos, transform.position) <= proximityRevealDist) return false;
        return IsCrouching && (_footInGrass || _graceTimer > 0f);
    }
}

TypeScript (Web / Phaser)

stealth-trigger-check.ts
export function evaluateStealthHidden(params: {
  toeInBox: boolean;
  isCrouching: boolean;
  exitGraceMs: number;
  guardDistancePx: number;
  proximityRevealPx: number;
}): boolean {
  if (params.guardDistancePx <= params.proximityRevealPx) return false;
  if (!params.isCrouching) return false;
  return params.toeInBox || params.exitGraceMs > 0;
}

DEVELOPER FAQ

Tuning, Edge Cases & Engine Integration FAQ

Why do games test the player’s foot collider instead of the full mesh for stealth grass?

Testing the foot/toe collider against an explicit `Area2D` / `TriggerBox` guarantees consistent stealth behavior regardless of cape physics, weapon length, or idle head bobbing.

What is Stealth Coyote Time and why do AAA games use it?

When a player accidentally brushes 2 pixels outside a bush boundary, a 320–420ms grace timer keeps stealth active long enough to step back in—eliminating frustrating instant-alert deaths.

How should guard vision cones fill a suspicion gauge?

Scale fill speed inversely with distance (`fillRate = baseRate * clamp(maxRange / dist, 0.7, 2.8)`) and decay suspicion smoothly when LOS breaks, showing clear `? -> ?? -> !` states.

How do I debug stealth trigger boxes during level design?

Keep an in-game wireframe toggle rendering green (active) vs red (inactive) trigger bounds alongside guard FOV cones so designers catch visual-vs-collider drift immediately.

Related Engine Hubs, Guides & Production Kits

More interactive labs in this track

Extracted from a real game · Zhaoshi Wulin

Every formula in these labs ships inside our upcoming Steam wuxia deckbuilder

3 martial-arts characters, 39 enemies, 70 relics, 19 kungfu finishers built in Godot with AI agents. Every time we solve a hard design or feel problem, we turn it into an interactive lab and skill here.