I’ve been working on an AI that roams around a fairly big map, opening doors and using elevators etc etc.
It has several pathfinding modifiers that it used to take into account, but it has recently just stopped for some odd reason.
local agentParams = {
AgentRadius = 2;
AgentHeight = 5;
AgentCanJump = true;
WaypointSpacing = 4;
Costs = {
Lava = math.huge;
Grass = math.huge;
Dirt = math.huge;
Mud = math.huge;
Ground = math.huge;
Door = 50; -- doors
MoveIdiot = 100; -- elevators
MoveIdiot2 = 100; -- elevators
MoveIdiot3 = 100; -- elevators
}
}
Path it makes
It always uses the pathfinding params.
After a while it just completeley dies lol
Before this bug, there was another bug where pathfinding just straight up didn’t work at all, this was due to a single tiny little part that was under the part destroy limit. Not sure why that bug hasn’t been fixed yet, but either way, I have not modified the pathfinding script and yet it is doing this for no apparent reason, any tips?
I’m not entirely convinced this is a pathfinding service bug, but if it is I’ll change the cat.
If you’re interested here’s the pathfinding function:
The pathfinding function
local function followPath(destination)
local success, err = pcall(function()
path:ComputeAsync(hrp.Position,destination)
end)
if success and path.Status == Enum.PathStatus.Success then
print("Moving to ",target)
waypoints = path:GetWaypoints()
local near = visualizeWaypoints(waypoints,destination)
print(near)
-- hrp.CFrame = CFrame.new(waypoints[near].Position)
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
followPath(destination)
end
end)
if not reachedConnection then
reachedConnection = hum.MoveToFinished:Connect(function(reached)
if waypoints[nextWaypointIndex].Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
if reached and nextWaypointIndex < #waypoints then
nextWaypointIndex += 1
--if inSight(destination.Parent) then
-- local backWaypoint = nextWaypointIndex - 4
-- hrp.CFrame = CFrame.new(waypoints[backWaypoint].Position)
-- --hum:MoveTo(waypoints[backWaypoint].Position)
-- reachedConnection:Disconnect()
-- blockedConnection:Disconnect()
-- reachedConnection = nil
-- blockedConnection = nil
-- return
--end
if waypoints[nextWaypointIndex].Label == "Door" then
open()
elseif waypoints[nextWaypointIndex].Label == "Teleport" then
-- teleport()
elseif waypoints[nextWaypointIndex].Label == "PushDoor" then
-- pushDoor()
hum:MoveTo(waypoints[nextWaypointIndex].Position)
elseif waypoints[nextWaypointIndex].Label == "MoveIdiot" then
task.wait(.6)
local model = game.Workspace.Zones.ElevatorHub.Elevator1.ElevatorDoors1
local Doors = model:WaitForChild("Doors")
local Door1 = Doors:WaitForChild("Door1")
local Door2 = Doors:WaitForChild("Door2")
local OpenTime = model:WaitForChild("OpenTime")
local OpenSound = Door1:WaitForChild("OpenSound")
local CloseSound = Door1:WaitForChild("CloseSound")
local DoorsOpen = model:WaitForChild("DoorsOpen")
DoorsOpen.Value = false
if not DoorsOpen.Value then
-- ClickSound:Play()
else
--if not ErrorSound.Playing then
--ErrorSound:Play()
--end
end
if DoorsOpen.Value == false then DoorsOpen.Value = true
OpenSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(-0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(0.25,0,0)
end
task.wait(.5)
hum:MoveTo(waypoints[nextWaypointIndex].Position)
wait(OpenTime.Value)
CloseSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(-0.25,0,0)
end
wait(CloseSound.TimeLength)
DoorsOpen.Value = false
end
elseif waypoints[nextWaypointIndex].Label == "MoveIdiot2" then
task.wait(8)
script.Parent:SetPrimaryPartCFrame(game.Workspace.PathfindingTP.End.CFrame)
hum:MoveTo(waypoints[nextWaypointIndex].Position)
elseif waypoints[nextWaypointIndex].Label == "MoveIdiot3" then
task.wait(.6)
local model = game.Workspace.Zones.ElevatorHub.Elevator2.ElevatorDoors2
local Doors = model:WaitForChild("Doors")
local Door1 = Doors:WaitForChild("Door1")
local Door2 = Doors:WaitForChild("Door2")
local OpenTime = model:WaitForChild("OpenTime")
local OpenSound = Door1:WaitForChild("OpenSound")
local CloseSound = Door1:WaitForChild("CloseSound")
local DoorsOpen = model:WaitForChild("DoorsOpen")
DoorsOpen.Value = false
if not DoorsOpen.Value then
-- ClickSound:Play()
else
--if not ErrorSound.Playing then
--ErrorSound:Play()
--end
end
if DoorsOpen.Value == false then DoorsOpen.Value = true
OpenSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(-0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(0.25,0,0)
end
task.wait(.5)
hum:MoveTo(waypoints[nextWaypointIndex].Position)
wait(OpenTime.Value)
CloseSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(-0.25,0,0)
end
wait(CloseSound.TimeLength)
DoorsOpen.Value = false
end
elseif waypoints[nextWaypointIndex].Label == "MoveIdiot4" then
task.wait(.6)
local model = game.Workspace.Zones.ElevatorHub.Elevator2.ElevatorDoors2
local Doors = model:WaitForChild("Doors")
local Door1 = Doors:WaitForChild("Door1")
local Door2 = Doors:WaitForChild("Door2")
local OpenTime = model:WaitForChild("OpenTime")
local OpenSound = Door1:WaitForChild("OpenSound")
local CloseSound = Door1:WaitForChild("CloseSound")
local DoorsOpen = model:WaitForChild("DoorsOpen")
DoorsOpen.Value = false
if not DoorsOpen.Value then
-- ClickSound:Play()
else
--if not ErrorSound.Playing then
--ErrorSound:Play()
--end
end
if DoorsOpen.Value == false then DoorsOpen.Value = true
OpenSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(-0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(0.25,0,0)
end
task.wait(.5)
hum:MoveTo(waypoints[nextWaypointIndex].Position)
wait(OpenTime.Value)
CloseSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(-0.25,0,0)
end
wait(CloseSound.TimeLength)
DoorsOpen.Value = false
end
elseif waypoints[nextWaypointIndex].Label == "MoveIdiot5" then
task.wait(8)
script.Parent:SetPrimaryPartCFrame(game.Workspace.PathfindingTP2.End.CFrame)
hum:MoveTo(waypoints[nextWaypointIndex].Position)
elseif waypoints[nextWaypointIndex].Label == "MoveIdiot6" then
task.wait(.6)
local model = game.Workspace.Zones.ElevatorHub.Elevator1.ElevatorDoors1
local Doors = model:WaitForChild("Doors")
local Door1 = Doors:WaitForChild("Door1")
local Door2 = Doors:WaitForChild("Door2")
local OpenTime = model:WaitForChild("OpenTime")
local OpenSound = Door1:WaitForChild("OpenSound")
local CloseSound = Door1:WaitForChild("CloseSound")
local DoorsOpen = model:WaitForChild("DoorsOpen")
DoorsOpen.Value = false
if not DoorsOpen.Value then
-- ClickSound:Play()
else
--if not ErrorSound.Playing then
--ErrorSound:Play()
--end
end
if DoorsOpen.Value == false then DoorsOpen.Value = true
OpenSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(-0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(0.25,0,0)
end
task.wait(.5)
hum:MoveTo(waypoints[nextWaypointIndex].Position)
wait(OpenTime.Value)
CloseSound:Play()
for i = 1, 23 do wait(1/60)
Door1.CFrame = Door1.CFrame*CFrame.new(0.25,0,0)
Door2.CFrame = Door2.CFrame*CFrame.new(-0.25,0,0)
end
wait(CloseSound.TimeLength)
DoorsOpen.Value = false
end
else
hum:MoveTo(waypoints[nextWaypointIndex].Position)
hum.MoveToFinished:Wait()
end
else
wait(3)
reachedConnection:Disconnect()
blockedConnection:Disconnect()
reachedConnection = nil
blockedConnection = nil
if #lookingPlrs > 0 then
-- Spook players
for i,v in pairs(lookingPlrs) do
game.ReplicatedStorage.Remotes.LookedAt:FireClient(v)
end
wait(6)
script.Parent:SetPrimaryPartCFrame(game.Workspace.NpcHome.CFrame)
wait(600)
local node = targets[math.random(1,#targets)]
script.Parent:SetPrimaryPartCFrame(node.CFrame)
target = targets[math.random(1,#targets)]
followPath(target.Position)
else
target = targets[math.random(1,#targets)]
followPath(target.Position)
end
-- local randX = math.random(-100,100)
-- local randZ = math.random(-100,100)
-- target = hrp.Position + Vector3.new(randX,0,randZ)
--followPath(target)
-- target = targets[math.random(1,#targets)]
--followPath(target.Position)
end
end)
end
nextWaypointIndex = 2
hum:MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path Failed",err)
print(target," Failed")
target = targets[math.random(1,#targets)]
followPath(target.Position)
end
end