AI Pathfinding Help

I am trying to learn pathfinding service, and have done well I feel. However; I wish to know how to make the AI actually follow a set path. Currently, the AI can move from one part to another easily, but does not follow a set path. It just does what it must to get there. Here is the code:

local PFS = game:GetService(‘PathfindingService’)
local zombie = game.Workspace.Zombie
local humanoid = zombie.Humanoid
local destination = game.Workspace.End

local path = PFS:CreatePath()

path:ComputeAsync(zombie.HumanoidRootPart.Position, destination.Position)

local waypoints = path:GetWaypoints()

for _, waypoint in pairs(waypoints) do
local part = Instance.new(“Part”)
part.Shape = “Ball”
part.Material = “Neon”
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace

humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end

1 Like

Path finding Service singleton does not follow a preset path, it simply finds the shortest path possible if that answers your question. If you want to create a specific path, like in cut scenes, you’ll have to make a path manually if I’m not wrong

1 Like

PathfindingService creates a set of waypoints for you to cycle through to properly move a character from one point or another. If you want to use a preset path, PathfindingService is irrelevant. Simply replace the waypoints generated from the PathfindingService with the waypoints you want to use for your preset path.

If you’re looking to make a repeated path, like a guard for example, patroling an area, you could create your own path following simply creating your own nodes with parts, and have the guards humanoid moveto target the first node and cycle through all nodes until it reaches its last node, and repeat.

1 Like