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

AI Pathfinding not correcting path even though being restarted multiple times?

I have created a little script that will restart the path of my AI every second so that it will automatically correct itself if it gets stuck, and also so that it can switch between targets if one gets closer than the current target (that part's not coded yet). So, here's the issue. It still gets stuck on corners, which is fine, except that the new paths don't avoid the wall/corner it's stuck on, it just continues to attempt to run through them. Why?

local tic = 0
local pathfindingservice = game:GetService("PathfindingService")
local pathfindingparameters = {
    ["AgentHeight"] = 6.8,
    ["AgentRadius"] = 3,
    ["AgentCanJump"] = false
}

local corotine = coroutine.create(function()
    while wait(1) do
        tic = tic + 1
    end
end)

coroutine.resume(corotine)

function createpath(scploc,targetloc)
    local path = pathfindingservice:CreatePath(pathfindingparameters)
    path:ComputeAsync((scploc + Vector3.new(-500,0,0)), (targetloc + Vector3.new(-500,0,0)))
    return path
end

while mode.Value == 3 do
    for index, waypoint in pairs (createpath(hrp.Position, game.Workspace.TARGET.Position):GetWaypoints()) do
    human:MoveTo(waypoint.Position + Vector3.new(500,0,0))
    human.MoveToFinished:wait()
    if tic >= 1 then
        tic = 0
        break
    end
end
end

1 answer

It's because you are adding that Vector3 on lines 19 and 25. Honestly I have no idea why you have those there but if you remove all 3 occurrences then it will work.

1 comment

0

I figured it out, and it wasn't actually this issue. This was 100% intentional, because I had a second maze in that spot. I'm doing that so my AI can pathfind through doors on the map. (That secondary map 500 blocks away has no doors, so the pathfinding happens there and then is translated back over, and the AI walks around ignoring the doors)

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