Trying to make pathfinding monster go through a door

I’m currently making an AI monster that chases players and I’m trying to make it go through doors. I would make the door have no collision, but I need it to collide with players so instead I’m using collision groups. However roblox’s pathfinding is…not great when it comes to collision groups. In order to get around this, I’m using pathfinding modifiers to try and trick the pathfinding to go through the door.

The problem is, for whatever reason it only works once.


Literally have no idea why the AI does this so yeah that sucks…

Here are some of the functions I used, however this isn’t all of my code.

for i, child in pairs(game.Workspace.DoorTest.DoorModel:GetChildren()) do
		local DoorModifier = Instance.new("PathfindingModifier", child)
		DoorModifier.Label = "Door1"
		DoorModifier.PassThrough = true
end
local function getPath(destination)

	local pathParams = {
		["AgentHeight"] = 7,
		["AgentRadius"] = 9,
		AgentCanJump = false,
		Costs = {
			Door1 = 0.01,
		}
	}
	local path = PathfindingService:CreatePath(pathParams)
	path:ComputeAsync(monster.HumanoidRootPart.Position, destination.Position)
	return path
end
local function walkTo(destination)
	local path = getPath(destination)
	if path.Status == Enum.PathStatus.Success then
		for index, waypoint in pairs(path:GetWaypoints()) do
			local target = findTarget()
			humanoid.WalkSpeed = 14
			if target and target.Humanoid.Health > 0 then
				humanoid.WalkSpeed = 30
				Attack(target)
				break
			end
			humanoid:MoveTo(waypoint.Position)	
			humanoid.MoveToFinished:Wait()
		end
	else
		humanoid:MoveTo(destination.Position - (monster.HumanoidRootPart.CFrame.LookVector * 10))
		humanoid.WalkSpeed = 14
	end

end
local function roam()
	local waypoints = workspace.Waypoints:GetChildren()
	local randomNum = math.random(1, #waypoints)
	walkTo(waypoints[randomNum])
end


while wait() do
	print("ROAMING!")
	roam()
end

Any help would be amazing, just pointing me in the right direction would be great. Thanks :smiley:

You you should check out Teddy a piggy styled horror game that is uncopylocked, you could also check out Gnome Code’s tutorial on how he created his game and the A.I

2 Likes

The code I have is a heavily modified version of his code, still couldn’t fix it.

What modifications did you make to the A.I was it procedural pathfinding?

The modifications I made were mostly animation based, things like a running animation, jumpscare animation etc. Pathfinding wise though, it functions similarly to Gnome’s code.

1 Like

have you tried making the cost 0
edit: also you can try to ‘trick’ it better by making its agent width smaller so it thinks it isn’t as big as it really is, thus allowing it to attempt to squeeze between spaces like the door

1 Like

Try to add a --humanoid.MoveToFinished:Wait() after the MoveTo() in the else statements.

try Changing the AgentHeight to = 3 and AgentRadius to = 4 that’s what I did to make a large monster navigate through a narrow hallway for my horror game

Thank you for all these replies, I’ll try these soon :upside_down_face:

not sure if you solved it yet but you could make a localscript in the startergui that does a while wait() loop and enables collisions for doors

idk if this is late, try putting a “Pathfinding Modifier” object and enable “PassThrough” property

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.