I have been trying my luck with the pathfinding service , using it to have NPC’s chase players. I notice there is no mention in the documentation regarding using the service for moving targets. It seems it delivers a set of waypoints, not much more. It is left up to us to develop the rest. After coming across several problems, I reduced my trial and error down to an NPC trying to find a stationary object. What I have tried so far
have an NPC find an object in a 5x5 generated maze.
this works - 103 waypoints were generated and the NPC could find the target
local PathfindingService = game:GetService("PathfindingService")
-- Variables for the zombie, its humanoid, and destination
local zombie = game.Workspace.RoblotGold
local humanoid = zombie.Humanoid
local destination = game.Workspace.Destination
-- Create the path object
local path = PathfindingService:CreatePath()
-- Compute the path
path:ComputeAsync(zombie.HumanoidRootPart.Position, destination.Position)
-- Get the path waypoints
local waypoints = path:GetWaypoints()
-- Get the path waypoints
local waypoints = path:GetWaypoints()
wait(15)
--print("here we go. there are this many waypoints : "..#waypoints)
if path.Status == Enum.PathStatus.Success then
print("path successfully deterimned with "..#waypoints.." waypoints")
elseif path.Status == Enum.PathStatus.NoPath then
print("path could not be determined")
else
print("huh")
end
-- Loop through waypoints
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
-- Move zombie to the next waypoint
humanoid:MoveTo(waypoint.Position)
-- Wait until zombie has reached the waypoint before continuing
humanoid.MoveToFinished:Wait()
end
Is there something I missed or is the roblox pathfinding service really as bad as it seems.
I guess I am looking for hope that I the service actually really fabulous and I have overlooked something by someone pointing out to me how it is supposed to be done.
Have you tried moving where the zombie is pathfinding to? PathfindingService can be weird sometimes in that it just doesn’t register that certain areas exist.
Even correcting for the double destination it doesn’t work. Personally if you’re doing a maze like this I would use A* pathfinding. I feel Roblox’s path finding service is best suited to larger open maps.
I have had problems with pathfinding service when I put in agent pathParams it sometimes can’t seem to do seemingly easy paths.
Idk if this would help but if you go to Studio settings and go to Studio tab. Scroll down and then you will see the Pathfinding mesh. If you tick that it will show where a humanoid can and can’t go.
The default pathfinding service sucks imo. Better use A*
I feel it depends on your experience - I’ve got Roblox’s PathFindingService working perfectly. But that’s because my map is terrain (1024*512) and I created invisible barriers to determine cliffs etc.
But for a map that requires a more defined or restricted path (like a maze or dungeons etc) you are better using A*. I’ve amended your code to include an A* script and added some nodes.
hi pjhinthehouse, I tried your solution and the project file is working well. the thing is, I am generating a new maze dynamically. I am trying out this node plugin and it seems the nodes are manually laid out ahead of time.
On the other hand I like the A* algorithm and maybe could use that by itsself. I will go back to the drawing board now…
Suggest you automate node creation and connections in a grid and then use A*. You could probably script it to find all nodes in a radius and connect them together.