Vi3W
Skip to content

Guides

Roblox NPC pathfinding: make an enemy that chases players

Build Roblox NPCs with PathfindingService: agent settings, waypoints, blocked paths, costs and modifiers, performance and common fixes.

3 min read

A simple low-poly figure following a glowing dotted path around obstacles through a low-poly maze
Illustration. Waypoints around obstacles, recomputed when blocked.

Quick answer

How do you make an NPC follow a player in Roblox?

Use PathfindingService. Create a path with agent settings (radius, height, jumping), compute it from the NPC to the player, then walk the NPC's Humanoid through each waypoint. Recompute the path every so often, and whenever the Blocked event fires. Keep paths under 3,000 studs, and only pathfind when a straight line won't do.

The basics

From Roblox's pathfinding docs:

  1. PathfindingService:CreatePath(agentParams) makes a path object.
  2. path:ComputeAsync(startPosition, goalPosition) calculates the route.
  3. Check path.Status is Success.
  4. path:GetWaypoints() gives positions from start to end. Each has an Action, such as Jump.
  5. Move the NPC's Humanoid to each waypoint in turn, jumping when told to.

Agent settings

  • AgentRadius: default 2, the clearance from walls
  • AgentHeight: default 5, so gaps lower than this are blocked
  • AgentCanJump: default true
  • AgentCanClimb: default false
  • WaypointSpacing: default 4
  • Costs: make some materials or zones more or less attractive

Match these to your NPC. A big monster needs a bigger radius and height, or it'll try to squeeze through doors it can't fit.

A top-down maze with a glowing path line weaving around walls
Illustration. Waypoints route around walls.

Chasing a moving player

Players move, so a path goes stale. A common loop:

  • If the NPC can see the player directly (a raycast with nothing in between), just walk straight at them. That's cheaper and smoother.
  • Otherwise, recompute the path every half-second to second, and walk the first few waypoints.
  • Connect path.Blocked and recompute when something blocks a waypoint ahead.

Steering the route

  • Material costs: all materials cost 1 by default. Set Water to a high cost to avoid it, or math.huge to forbid it.
  • PathfindingModifier: label an area, such as DangerZone, and give it a cost. Turn on PassThrough to let paths cross things like doors.
  • PathfindingLink: connect two points the navmesh doesn't, like a ladder or a boat ride.

Common problems

  • "No path": goal too far (direct distance over 3,000 studs), the node budget ran out on a complex map, or the agent settings make the route impossible.
  • NPC stops and stares: the NPC is anchored, or the next waypoint is unreachable. Recompute.
  • NPC gets stuck on corners: increase AgentRadius.
  • Client-side pathfinding fails: with StreamingEnabled, targets may not be loaded. Run NPC pathfinding on the server (StreamingEnabled).

Performance

Pathfinding is relatively expensive. With many NPCs:

  • Stagger recomputes so they don't all happen on one frame.
  • Use direct movement whenever there's line of sight.
  • Put sleeping NPCs to rest when no players are near.

The NPC's body

An NPC needs a rigged body to walk convincingly: a Humanoid rig, or a custom rig with an AnimationController. See character models and custom rig not animating.

Make the NPC body in Vi3W

Vi3W turns prompts, concept art or sketches into textured, retopologised meshes (GLB, FBX or OBJ) for monsters, guards and creatures. Rig them with Avatar Setup or Blender, then add the pathfinding above. Vi3W doesn't rig or animate. Make an NPC in Vi3W.

Last reviewed