Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I use Pathfinding?

I am making a boss battle where the boss goes about his maze randomly, but I can't seem to figure out how to use PathfindingService correctly.

local pathservice = game:GetService("PathfindingService")


local path = pathservice:ComputeRawPathAsync(script.Parent.Torso.Position, 	game.Workspace.Stop.Position, 100000)
script.Parent.Humanoid:MoveTo(path)

Errors: Unable to cast Instance to Vector3

1 answer

✓ Accepted answer

The path value I believe is an instance. Isn't there a function for the path itself to get all the points?

EDIT:

read this: http://wiki.roblox.com/index.php?title=Pathfinding#Using_a_path there is a function

-- replace your moveto(path) line with this:
points = path:GetPointCoordinates()
for _, vec3 in ipairs(points) do
	script.Parent.Humanoid:MoveTo(vec3)
end

also try setting stop's position to a random value between the edges of your map so it won't try to leave the map (not that it will as it just won't do anything)

1 comment

0

Tell me if this helped you! I would be glad to hear you accept it.

This discussion is preserved as it was. New answers, comments, and votes are closed.