What are you attempting to achieve?
Villager Ai with Pathfinding.
What is the issue?
Pathfinding seems to be broken for me…
whenever I call path:GetWaypoints()
it returns an empty table.
What solutions have you tried so far?
- The pathfinding api on the Roblox wiki
- The pathfinding method used in this old 2014 Roblox tutorial video
- Various other methods
Links
- Wiki: Character Pathfinding | Documentation - Roblox Creator Hub
- Video: https://www.youtube.com/watch?v=pQ9Mcc-5UuA
Code
-- dispeller
-- Villager AI
--https://developer.roblox.com/en-us/articles/Pathfinding
local PathfindingService = game:GetService("PathfindingService")
local NPC = script.Parent
local humanoid = NPC.Humanoid
function walkTo(destination)
-- Create the path object
local path = PathfindingService:CreatePath()
-- Compute the path
path:ComputeAsync(NPC.HumanoidRootPart.Position, destination)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
-- Loop through waypoints
warn('###'..#waypoints)
for _, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
--humanoid.WalkToPoint = waypoint.Position
humanoid.MoveToFinished:Wait()
print('OK: '..tostring(waypoint.Position))
--wait(15)
end
end
--[[
function walkTo(pos)
--humanoid.WalkToPoint = pos
humanoid:MoveTo(pos)
humanoid.MoveToFinished:Wait()
end
--]]
walkingAroundRandomly = true
local points = workspace.PrimisTown.VillagerWalkingPoints:GetChildren()
while wait() do
if walkingAroundRandomly then
local target = math.random(1,#points)
local point = points[target]
walkTo(point.Position)
end
end
help