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