Hey guys it’s agKing here and I have a problem with the pathfinding service so basically I’m making a brainrot game in which I want NPCs to go to my plot and to the TeleportPart but then some NPCs run into obstacles along the way such as Wall, Trees etc. and it’s very annoying, I’ve tried changing some parameters of the agent and it doesn’t seem to change anything at all. I’ve did some research and some people says that PathfindingService seems to struggle with meshparts as our game consists of lots of Meshparts done in blender.
Here’s the video showing the NPC stupid behavior
Here’s the code of the agent. I’ve tried following the code of a blog for when the npc struggle to go to its destination to recalculate the path but that doesn’t seem to work either
function CharacterHandler:MoveThrough(destinations)
local hum = script.Parent:FindFirstChild("Humanoid")
local root = script.Parent:FindFirstChild("HumanoidRootPart")
if not hum or not root then return end
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
local AGENT_PARAMS = {
AgentRadius = 5,
AgentHeight = 5,
AgentCanJump = true,
AgentJumpHeight = 10,
AgentMaxSlope = 45,
WaypointSpacing = 6
}
task.spawn(function()
for _, destination in ipairs(destinations) do
local function navigateTo(dest)
local path = PathfindingService:CreatePath(AGENT_PARAMS)
local success, err = pcall(function()
path:ComputeAsync(root.Position, dest.Position)
end)
if not success or path.Status ~= Enum.PathStatus.Success then
warn("Path failed to "..dest.Name..":", path.Status)
return
end
-- Connexion pour gérer les blocages
local blockedConn
blockedConn = path.Blocked:Connect(function()
blockedConn:Disconnect()
navigateTo(dest) -- recalcul si bloqué
end)
-- Suivi du chemin
for _, wp in ipairs(path:GetWaypoints()) do
if wp.Action == Enum.PathWaypointAction.Jump then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
hum:MoveTo(wp.Position)
hum.MoveToFinished:Wait()
end
blockedConn:Disconnect()
end
navigateTo(destination)
end
end)
end
Hey there. Since your research yielded the conclusion that mesh parts cause issues in pathfinding, I would recommend you create a part with the same size and position as the mesh part. You can then set the transparency to 1 and have it as sort of a “hitbox.” This way, pathfinding won’t be struggling to calculate with the mesh part—it will only need to calculate with the hitboxes.
I wonder if I would have to find my own pathfinding algorithm but it’s going to take a massive time investment from me and I’m not sure if I’m ready to invest this time and energy into making my own solution. I’ve looked up in the internet and I’ve found the A* algorithm
I changed it to 1 still problem remains I tried one time adding a Cost parameter table in which I would add the part that my humanoid I want to avoid but actually I’m not sure to understand the Costs parameters anyway