I am trying to make an npc ignore doors in its pathfinding so it can walk through them using the new pathfinding modifiers, but I can’t seem to figure out how to use them. He still justs walks around the wall with the door like this:
https://gyazo.com/18c2e9989e37e9f44f84b0eda9a7834a
Here is the script:
local hum = script.Parent.Humanoid
local root = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local goal = workspace.Goal.Position
local modifier = Instance.new("PathfindingModifier")
modifier.ModifierId = "Door"
modifier.Parent = workspace.Door
local agentparams = {
AgentRaduis = 2,
AgentCanJump = false,
Costs = {
Door = 1.0
}
}
local path = game:GetService("PathfindingService"):CreatePath(agentparams)
local visualizepoints = true
path:ComputeAsync(root.Position, goal)
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
if visualizepoints == true then
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position + Vector3.new(0, 2, 0)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
end
hum:MoveTo(waypoint.Position)
hum.MoveToFinished:Wait()
end
The door is a model and the door is set to open when the character touches any of its parts in the model.
koziahss
(Agent_Invalid)
December 15, 2021, 5:43pm
#2
Have you made sure to tick PassThrough on the Pathfinding modifier?
FunAsiK
(FunAsiK)
December 15, 2021, 5:50pm
#3
As koziahss already said.
I don’t see you enable true on PassThrough?
local modifier = Instance.new("PathfindingModifier")
modifier.ModifierId = "Door"
modifier.PassThrough = true
modifier.Parent = workspace.Door
I set it to true but the npc still goes around the door, does the modifier work for models?
FunAsiK
(FunAsiK)
December 15, 2021, 6:00pm
#5
I’m not very good at pathfinding, but no, it doesn’t work on the model.
But you can use for i,v in pairs() loop:
for _, door_part in pairs(workspace.Door:GetDescendants()) do
if door_part:IsA("BasePart") or door_part:IsA("MeshPart") then
local modifier = Instance.new("PathfindingModifier")
modifier.ModifierId = "Door"
modifier.PassThrough = true
modifier.Parent = door_part
end
end
This is the first thing that came to my mind.
3 Likes
So do I need to just create separate modifiers for each individual part in the model? I can’t really do that since there will be alot of doors on the map, is there any alternative?
I tried creating a part called doorvolume sort of like the example shown in the post showcasing the new modifiers but it still doesn’t work:
local hum = script.Parent.Humanoid
local root = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local goal = workspace.Goal.Position
local modifierVolume = workspace.Door.DoorVolume
local modifier = Instance.new("PathfindingModifier", modifierVolume)
modifier.ModifierId = "Door"
modifier.PassThrough = true
modifier.Parent = workspace.Door
local agentparams = {
AgentRaduis = 2,
AgentCanJump = false,
Costs = {
Door = 0
}
}
local path = game:GetService("PathfindingService"):CreatePath(agentparams)
local visualizepoints = true
path:ComputeAsync(root.Position, goal)
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
if visualizepoints == true then
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position + Vector3.new(0, 2, 0)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
end
hum:MoveTo(waypoint.Position)
hum.MoveToFinished:Wait()
end
I have tried with a cost of 0, 0.5, and 1.0 and still he just wont try it
Your edit worked! He finally paths to the doors now! Thanks!
FunAsiK
(FunAsiK)
December 15, 2021, 6:14pm
#9
Have you tried manually adding PathfindingModifier? If that doesn’t work, then I don’t even know what it might be.
FunAsiK
(FunAsiK)
December 15, 2021, 6:15pm
#10
I’m glad that helped, good luck!