Basically I want to make a pathfinder and put it to an npc, but this pathfinder can detect the edges of the map, to avoid falling, I already have the script done, what should I add to achieve this?
SCRIPT:
wait(0.1)
local pathFindingService = game:GetService("PathfindingService")
local path = pathFindingService:CreatePath()
path:ComputeAsync(workspace.testmy.HumanoidRootPart.Position, workspace.Goal.Position)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
if path.Status == Enum.PathStatus.Success then
if waypoint.Action == Enum.PathWaypointAction.Jump then
workspace.testmy.Humanoid.Jump = true
end
workspace.testmy.Humanoid:MoveTo(waypoint.Position)
workspace.testmy.Humanoid.MoveToFinished:Wait()
else
print("failed path")
break
end
end
You could utilize the new pathfinding modifiers (BETA). Otherwise, you could always just add invisible barriers around your map, and PathfindingService would have to find a way to avoid those barriers (if possible).