The arena is a grid navmesh. Each frame the NPC's behavior tree — a priority Selector — evaluates its children top to bottom and runs the first one whose condition holds: flee if health is low, attack if the player is within melee range, chase if the player is inside the detection radius, otherwise patrol between waypoints. Whenever the target cell (player position, a patrol waypoint, or a flee direction) changes, the NPC re-runs A* over the grid to find a new shortest walkable path and walks its waypoints in order.
f(n) = g(n) + h(n)
g = cost from start, h = Manhattan distance to goal
Selector: try Flee → Attack → Chase → Patrol, run first that succeeds
- NPC speed — how fast the agent moves along its current A* path.
- Detection radius — the NPC's field of view; stepping inside it flips Patrol → Chase.
- Navmesh — toggles the grid overlay; green tiles are walkable, dark tiles are blocked obstacles.
- A* path — toggles the highlighted line showing the currently planned route.
Real-world relevance: this Selector + A* pairing is the backbone of most game NPC AI — from stealth-game guards to RPG monsters — because it is cheap to run every frame, easy to author, and easy to debug by watching exactly which node is active.