roblox-npc-ai
Use when creating Roblox NPCs or enemies with pathfinding, state machines, line-of-sight or FOV detection, spawns, or AI update loops.
Install
npx skills add https://github.com/tabooharmony/roblox-brain --skill roblox-npc-aiSKILL.md
Roblox NPC & AI
When to Load
Load for NPCs/enemies: pathfinding, state machines, LOS/FOV detection, spawns, AI loops, or physics ownership.
Quick Reference
PathfindingService
local path = PathfindingService:CreatePath({
AgentRadius = 2, AgentHeight = 5, AgentCanJump = true,
Costs = { Water = 20, DangerZone = math.huge },
})
path:ComputeAsync(npcPos, targetPos)
if path.Status ~= Enum.PathStatus.Success then return end
for _, wp in path:GetWaypoints() do
if wp.Action == Enum.PathWaypointAction.Jump then humanoid.Jump = true end
humanoid:MoveTo(wp.Position)
if not humanoid.MoveToFinished:Wait() then return end
end
- Recompute on blocked with a bounded retry or cancellation policy.
- In Studio, test
Workspace.PathfindingUseImprovedSearchon representative maps before rollout; it is not scriptable. - Avoid long requests and repeated recomputation. Moving collidable geometry can trigger navigation-mesh work.
- Region modifiers: anchored part +
PathfindingModifierLabel → Costs PassThrough = truefor doors;PathfindingLinkfor disconnected navmeshmath.hugecost = non-traversable
State Machine
idle → patrol → chase → attack → flee → dead
- idle/patrol → chase (player detected) → attack (in range) → idle (lost)
- any → flee (health low) → idle (safe); any → dead (health ≤ 0)
- Transitions own movement changes, target cleanup, and cancellation
Detection (distance → FOV → LOS)
- Distance
(a-b).Magnitude: cheapest, always first - FOV
forward:Dot(toTarget)cosine; use a configured cone for your game, not a universal angle - LOS
workspace:Raycast: expensive, last
- If the design includes hearing or proximity detection, make it a separate configured signal rather than a universal FOV bypass.
Network Ownership
- Classic projects may use
SetNetworkOwner(nil)for physics-sensitive NPCs, but it is not complete security. In Server Authority projects, configure the authority model instead of treating network ownership as the security boundary.
Update Loop
- Throttle and stagger AI based on NPC count, path cost, and profiler evidence, not a universal tick rate. Keep NPC decisions and movement server-side; client code may handle presentation.
For spawners, lifecycle cleanup, timeout handling, and performance budgets, load references/full.md.
Related skills
godot-gdscript-patternswshobson16KMaster Godot 4 GDScript patterns including signals, scenes, state machines, and optimization. Use when building Godot games, implementing game systems, or learning GDScript best practices.game-enginegithub13KExpert skill for building web-based game engines and games using HTML5, Canvas, WebGL, and JavaScript. Use when asked to create games, build game engines, implement game physics, handle collision detection, set up game loops, manage sprites, add game controls, or work with 2D/3D rendering. Covers techniques for platformers, breakout-style games, maze games, tilemaps, audio, multiplayer via WebRTC, and publishing games.unity-ecs-patternswshobson11KMaster Unity ECS (Entity Component System) with DOTS, Jobs, and Burst for high-performance game development. Use when building data-oriented games, optimizing performance, or working with large entity counts.msw-defaultplayermsw-git7.9KMSW DefaultPlayer (character) management. Use the msw-general ModelBuilder to inspect/patch DefaultPlayer.model and Player.model, add/remove components, configure movement speed / jump force / HP / camera, and per-map-mode movement components. Use for DefaultPlayer model, player components, movement speed, jump force, HP, camera, physics. Keywords: player, DefaultPlayer, speed, jump, HP, camera, gravity, revive, respawn, character.
