Module 4 · In Studio · challenge 3 of 3 in this lesson
challenges/npc_pathfinding_work.luau implements nextState(state, facts) for the crawler's state table (stun overrides all, finished stun recovers to Idle, Attack <= 4 studs, Chase <= 40 studs, failed path or missing target goes Idle)
A test in Studio grades it and prints a pass code.
Open
Level 3, Professional
Challenge
Write the crawler's brain as two pure functions matching m08-crawler's CrawlerBrain. Start from the m14-ship tag in the game repo to get challenges/npc_pathfinding_work.luau and challenges/npc-pathfinding.luau, edit challenges/npc_pathfinding_work.luau, and run game.ServerScriptService.RunGameTests:Invoke("npc-pathfinding") from the command bar.
- Start from
- The game at milestone m14 (download)
- Grade it
- In Studio, press Play, then run
game.ServerScriptService.RunGameTests:Invoke("npc-pathfinding")in the server command bar. Copy the pass code from Output.
Done means
- challenges/npc_pathfinding_work.luau implements nextState(state, facts) for the crawler's state table (stun overrides all, finished stun recovers to Idle, Attack <= 4 studs, Chase <= 40 studs, failed path or missing target goes Idle)
- Its shouldRepath(now, lastPathAt, targetMoved, blockedAhead) re-paths immediately when blockedAhead is true, or when now - lastPathAt >= 0.5 and targetMoved >= 6
- challenges/npc-pathfinding.luau prints TEST PASS for every check