Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pathfinding, Doesn't go around the walls?

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

I suggest taking a look at and utilizing Pathfinding Service: https://developer.roblox.com/en-us/articles/Pathfinding

Ad

Answer this question