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

Pathfinding, Doesn't go around the walls?

Hey All,

I have made this Pathfinding script, but when it comes to going around parts it just doesn't. It tries to walk through the part.

https://ibb.co/R7Yx7H0

See this link above, The yellow line is what I expected it to do, but it's doing the blue line.

local NPC = script.Parent
local humanoid = NPC.Humanoid
local CollectionService = game:GetService("CollectionService")
local TaggedParts = CollectionService:GetTagged("Dirt")
local active = true

	while active == true do
				wait()
				local Closest
				local PlayerPosition = NPC.PrimaryPart.Position
				for _, TaggedPart in pairs(TaggedParts) do
					if Closest == nil then
					Closest = TaggedPart
						else
					if (PlayerPosition - TaggedPart.Position).magnitude < (Closest.Position - PlayerPosition).magnitude then
						Closest = TaggedPart
			end
	end
end

		if Closest ~= nil then
		for _, TaggedPart in pairs(TaggedParts) do
			if TaggedPart == Closest then
				humanoid:MoveTo(TaggedPart.Position)
				humanoid.MoveToFinished:wait()
			end
		end
	end
end

This is my code, am I missing a few lines or extra bit of code to make this work? If yes, could you please explain.

Thanks!

1 answer

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