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

Pathfinding zombie not following path?

Asked by 7 years ago

So I start the game the zombie will not move I can move it if I walk up to it and push it but it wont moveTo as I want following the path the path shows no errors hears the script.

local model = Instance.new("Model")
model.Name = "Points"
model.Parent = game.Workspace
while true do
    for i, v in pairs(game.Players:GetPlayers()) do
        local torsop = v.Character.Torso.Position
        local zombies = game.Workspace.Zombies:GetChildren()
        for i = 1, #zombies do
            if (zombies[i].Torso.Position - torsop).magnitude < 500 then
                repeat 
                    local pathfinding = game:GetService("PathfindingService")
                    function vpath(path)
                        model:ClearAllChildren()
                        points = path:GetPointCoordinates()
                        for _, point in ipairs(points) do
                            local part = Instance.new("Part")
                            part.FormFactor = Enum.FormFactor.Custom
                            part.Size = Vector3.new(0.5,0.5,0.5)
                            part.Position = point
                            part.Anchored = true
                            part.CanCollide = false
                            part.Parent = model
                        end 
                    end
                local start = script.Parent.Torso.Position
                local Target = v.Character.Torso.Position
                local path = pathfinding:ComputeRawPathAsync(start, Target, 500)
                vpath(path)
                coroutine.resume(coroutine.create(function()
                    while true do
                        local check = points:GetChildren()
                        if #check > 0 then
                            for _, poi in ipairs(points) do
                                script.Parent.Humanoid:MoveTo(poi)
                            end 
                        end
                    wait(.1)
                    end
                end))
                if path.Status == Enum.PathStatus.FailStartNotEmpty or path.Status == Enum.PathStatus.FailFinishNotEmpty then
                    print("Compute failed")
                    return {}
                end
                wait()
                until (start - Target).magnitude < 3 or v.Character.Humanoid.Health == 0
            else
                print("Not Close Enough!")
            end 
        end
    end
wait(.1)
end
0
overcomplicated ai lol RubenKan 3615 — 7y
0
You have made infinite loops in infinite loops?? You need to rethink this code. User#5423 17 — 7y
0
ok johndeer2233 439 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Uh, It seems to me you overthought your NPC. IT looks a bit overcomplicated and unecessary made than it should have been. And also had to many loops... inside loops..

0
This is not an answer, it should be a comment. awfulszn 394 — 7y
0
You literally just posted everything that was already said in the comments, too thehybrid576 294 — 7y
Ad

Answer this question