game-ai
Skill399 starsChanged 3 months agoMITView on GitHub
Design NPC and enemy decision-making with finite state machines, behavior trees, steering behaviors, and A* pathfinding — engine-neutral algorithms that pair with the detected engine's navigation API. Use when building enemy AI, an FSM or behavior tree, steering/flocking, or pathfinding, or when the user mentions state machine, behavior tree, blackboard, A*, navmesh, seek, or patrol/chase.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- gamedev-skills/awesome-gamedev-agent-skillstheir own version, first seen Nov 11, 2026
- poorvith-mp/skills-gamedevtheir own version, first seen Aug 19, 2026
- ukanwat/aaabenchword for word, first seen Aug 15, 2026
- ukanwat/overtimeword for word, first seen Aug 15, 2026
Other versions4 projects use a version of this.
Word for word · 2
- ukanwat/aaabench★ 399100% same
- ukanwat/overtime★ 399100% same
Edited · 0
None found.
Wrote their own version · 2
- gamedev-skills/awesome-gamedev-agent-skills★ 9ksame name
- poorvith-mp/skills-gamedev★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- audio-designSkill
- camera-systemsSkill
- dialogue-systemsSkill
- game-feelSkill
- game-ui-uxSkill
- input-systemsSkill
- level-designSkill
- performance-optimizationSkill
- physics-tuningSkill
- procedural-genSkill
- reference-imagesSkill
- save-systemsSkill
- shader-programmingSkill
- unreal-behavior-treesSkill
- unreal-blueprintsSkill
- unreal-cpp-gameplaySkill
- unreal-enhanced-inputSkill
- unreal-niagaraSkill
- unreal-packagingSkill
- overtime-docsSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Keep them decoupled — a behavior tree picks a target, the pathfinder produces waypoints, steering follows them.
- Distinctive: line 28
Use when implementing enemy/NPC logic: patrols, chase/flee, guard states, group movement, or "find a path to the player".
- Distinctive: line 30
Use to choose between an FSM (few clear states), a behavior tree (many reactive behaviors with priorities), or steering (smooth local …
- Distinctive: line 32
Use when integrating pathfinding: A* on a grid/graph, or driving an engine navmesh agent.
- Very specific: line 84
Keep transition logic *inside* states (or in a table), never as a growing pile of if flags.
- Distinctive: line 154
Steering straight to the goal: instead of to the next waypoint makes agents hug walls and corners.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Game AI: decisions, steering, and pathfinding
Build believable NPC behavior from three separable layers: decide (what to do), steer (how to move there), and path (how to route around the map). Keep them decoupled — a behavior tree picks a target, the pathfinder produces waypoints, steering follows them. This skill teaches the engine-neutral algorithms; bind them to your engine via the related skills below.
When to use
- Use when implementing enemy/NPC logic: patrols, chase/flee, guard states, group movement, or "find a path to the player".
- Use to choose between an FSM (few clear states), a behavior tree (many reactive behaviors with priorities), or steering (smooth local movement).
- Use when integrating pathfinding: A* on a grid/graph, or driving an engine navmesh agent.
When not to use: for the engine's concrete navmesh/agent API and baking,
use unity-navmesh, unreal-behavior-trees, or Godot's NavigationAgent2D/3D
(see that engine skill). For movement/collision feel, use physics-tuning. For
spawning waves along lanes, see the tower-defense genre skill.
Core workflow
- Pick the decision model by complexity. 2–5 states with obvious transitions → FSM. Many behaviors, priorities, interruption, reuse → behavior tree. Continuous "how strongly do I want each option" → utility scoring.
- Separate decision from motion. The decision layer outputs an intent (target position, action). Steering or pathfinding turns intent into motion.
- Path on the right graph. Grid tiles, waypoint graph, or a baked navmesh. Fewer nodes = faster A*. Prefer the engine's navmesh for 3D; A* on a grid for tile games.
- Steer along the path, not straight to the goal — follow the next waypoint, advancing when close, so agents round corners.
- Recompute paths sparingly. Pathfind on a timer or when the goal moves a tile, not every frame. Cache the path; only the waypoint index advances.
- Verify by observation. Watch the agent: does it reach the goal, get stuck on corners, oscillate between states? Draw the path and current state on screen while tuning.
Patterns
1. Finite state machine (one state object, explicit transitions)
# Each state is a small object with enter/update/exit. The machine owns "current".
class_name State
func enter(agent): pass
func update(agent, dt) -> State: return null # return a new state to transition
func exit(agent): pass
# --- Chase state: returns Patrol when the player escapes sight range ---
class Chase extends State:
func update(agent, dt) -> State:
if not agent.can_see(agent.target):
return Patrol.new() # transition by returning next state
agent.move_toward(agent.target.position, dt)
return null # null = stay in this state
# --- Driver: call once per frame ---
func tick(dt):
var next = current.update(self, dt)
if next != null:
current.exit(self); next.enter(self); current = nextKeep transition logic inside states (or in a table), never as a growing pile
of if flags. One state owns one behavior; that is what keeps an FSM readable.
2. Behavior tree tick (composite nodes return a status)
# A node's tick() returns SUCCESS, FAILURE, or RUNNING (still working this frame).
enum Status { SUCCESS, FAILURE, RUNNING }
# Sequence: run children in order; stop at the first non-SUCCESS (logical AND).
func sequence_tick(children, agent, dt) -> int:
for child in children:
var s = child.tick(agent, dt)
if s != Status.SUCCESS:
return s # FAILURE or RUNNING short-circuits the sequence
return Status.SUCCESS
# Selector: try children until one succeeds or is RUNNING (logical OR / fallback).
func selector_tick(children, agent, dt) -> int:
for child in children:
var s = child.tick(agent, dt)
if s != Status.FAILURE:
return s # SUCCESS or RUNNING stops the search
return Status.FAILUREA guard AI reads top-down: Selector[ Sequence[CanSeePlayer?, Chase], Patrol ]
— chase if visible, otherwise patrol. See references/behavior-trees.md for
leaf nodes, decorators (Inverter, Cooldown), and a blackboard.
3. Steering: seek and arrive (smooth, frame-rate independent)
# Seek: accelerate toward a target at full speed. Steering = desired - current.
func seek(pos, vel, target, max_speed, max_force) -> Vector2:
var desired = (target - pos).normalized() * max_speed
return (desired - vel).limit_length(max_force) # a force, not a teleport
# Arrive: like seek, but ramp speed down inside slow_radius so it stops cleanly.
func arrive(pos, vel, target, max_speed, max_force, slow_radius) -> Vector2:
var offset = target - pos
var dist = offset.length()
if dist < 0.001: return -vel # already there: kill drift
var ramped = max_speed * min(dist / slow_radius, 1.0)
var desired = offset / dist * ramped
return (desired - vel).limit_length(max_force)
# Per frame: vel += steering * dt; pos += vel * dt (always scale by dt)4. A* heuristic must not overestimate (or paths stop being shortest)
# Match the heuristic to the movement. An ADMISSIBLE heuristic (never larger
# than the true remaining cost) keeps A* optimal.
def heuristic(a, b):
dx, dy = abs(a.x - b.x), abs(a.y - b.y)
# return dx + dy # Manhattan: 4-direction grids (no diagonals)
return (dx + dy) + (1.414 - 2) * min(dx, dy) # octile: 8-direction grids
# f(n) = g(n) + h(n): g = cost from start, h = heuristic to goal.
# Overestimating h is faster but no longer guarantees the shortest path.The full A* loop (priority queue, came_from reconstruction, grid + waypoint
graphs) is in references/pathfinding.md.
Pitfalls
- Pathfinding every frame tanks the frame rate. Recompute on a timer or only when the target moves to a new tile; follow the cached waypoints in between.
- Steering straight to the goal instead of to the next waypoint makes agents hug walls and corners. Follow the path; advance the waypoint when within radius.
- Inadmissible A* heuristic (e.g. Euclidean distance scaled up, or Manhattan on a diagonal grid) returns fast but non-shortest paths. Pick the heuristic that matches your allowed moves.
- Behavior tree leaves that never return RUNNING for multi-frame actions (walking, playing an animation) cause the tree to restart the action every tick. Return RUNNING until the action completes.
- FSM transition spaghetti: scattering
if state == ...checks everywhere recreates the mess an FSM exists to prevent. Keep transitions in the state. - No line-of-sight or stuck check → agents grind into walls forever. Add a timeout that forces a repath or a state change.
References
references/pathfinding.md— complete A* (priority queue, reconstruction), grid vs waypoint graphs, when to defer to an engine navmesh.references/behavior-trees.md— node taxonomy, leaf/decorator implementations, blackboard, and FSM-vs-BT selection.
Related skills
unity-navmesh,unreal-behavior-trees— concrete engine AI/navigation APIs.physics-tuning— movement, collision response, and agent radius.procedural-gen— generating the graph/level the AI navigates.tower-defense,fps-shooter— genres that compose this skill.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

