AI sometimes runs into a wall


(Sorry for the intense visuals)

local PathfindingService = game:GetService("PathfindingService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local Pathfind = {}

local function findPath(hrp : BasePart,location : Vector3)
	local path : Path = PathfindingService:CreatePath({
		AgentCanJump = false,
		AgentCanClimb = false,
		WaypointsSpacing = math.huge,
		AgentRadius = 1,
		AgentHeight = 3,
	})
	path:ComputeAsync(hrp.Position,location)
	return path
end

Pathfind.Walk = function(character : Model, destination)
	
	if not character then return end
	
	local path : Path = findPath(character:WaitForChild("HumanoidRootPart"),destination)

	local humanoid:Humanoid = character:WaitForChild("Humanoid")

	local function followPath(destination)
		if not humanoid then return end
		if character:GetAttribute("Moving") then return end
		character:SetAttribute("Moving",true)
		
		warn(character.Name.." started moving")
		
		character:WaitForChild("HumanoidRootPart"):SetNetworkOwner()
		
		task.spawn(function()
			for i,points in pairs(path:GetWaypoints()) do
				humanoid:MoveTo(points.Position)
				humanoid.MoveToFinished:Wait()
			end

			warn(character.Name.." is done moving")
			character:SetAttribute("Moving",false)
			return "Done"
		end)
	end
	
	followPath(destination)

end

return Pathfind

Is it because the locker doors are very thin and Pathfinding doesn’t realize they are there?

Ummm, why is your WaypointSpacing = math.huge?

I just noticed that you misspelled WaypointsSpacing with an extra s in the middle.

You can also a transparent, CanCollide false wall around the lockers that uses a PathFinderModifier with its Cost set to math.Huge as explained at the end of this Pathfinding document.

1 Like

i did most of what you said and it mostly fixed my issue, but there is a very little chance that the ai will backtrack a lil bit

id recomend to use a series of attachments through the stages, literate through those, and move the entity with alignposition

What if you put slight angles at the walls of rooms where there are diagonal opposite doors to direct the AI away from spots that it might get trapped by?

Have you also tried increasing the AgentRadius parameter? I had a similar issue in the past, and increasing it to something like 3 would solve it.

if i were to do that, he wouldnt fit through the doors

Your AgentRadius is now 1, which means the smallest opening would be 2 studs across. What is the narrowest doorway in your place?
If it’s something over 6 studs wide then @doomguy2164’s suggestion would work, or if it’s over 8 studs then raising it to 4 would work.