Pathfinding ignores other npcs

I’m trying to use pathfinding service but I’ve noticed that it ignores other npcs while creating a path. I’m guessing same thing would happen with everything that has humanoid in it. Is there any way to fix it? This is causing them to stuck on each other sometimes

There are many topics located on DevForum that are similar to your problem. If those aren’t helpful, try this roblox wiki article: Character Pathfinding | Documentation - Roblox Creator Hub

why not use collision groups and prevent the npc’s from colliding with each other you can read more about them here: Collisions | Documentation - Roblox Creator Hub

2 Likes

Bumping this, since I don’t believe the issue has been resolved yet.

Dont know the reason of bumping, but pretty sure if youre using a tutorial pathfinding script there might be a part im the script that checks if the target is a player.

Examples are:

Using “Players:GetPlayers()” to get the target, or using :GetPlayerFromCharacter() to check if target is a player.

Edit:

Nvm, im dumb, the issue is that pathfinding currently doesnt detect humanoid models.

Theres currently no fixes. (That i know of

That really sucks- My game is based around NPC logic and it was doing fine until I encountered this issue.
I’m working on another approach considering welding a part to the NPC, as an external hitbox. It does seem to detect, and fixes the issue for npc’s without the external hitbox, though the pathfinding occasionally detects the hitbox within it’s own NPC. Is it possible to have pathfinding ignore a certain part without CanCollide being disabled?

Not sure, but i would think you would use Collision Groups? but, this might not work, as currently I think robloxs’ pathfinding service is inferior to other services, but theres not much we can do about it

Ah, I’ve tried collision groups in the past. Since NPC’s are moved at mass, in the game- They entirely ignore eachother and thus walk through eachother every chance that they get lol. It’s a good suggestion, but it’s just not what I’m looking for. I do have another idea considering ray-casts, but I’m not sure how this would be done as I haven’t really used em’

I don’t know if attaching a transparent part to the character model, with a pathfinding modifier on it would help, and then set the cost to be super high.

What do you mean cost exactly?

Raycasts. I hate them. But you can direct a raycast towards the closest player using unit, or just raycast infront of the npc.

-- look vector raycast
local ORIGIN = -- set origin to the npcs primary part
local DIRECTION = ORIGIN.CFrame.LookVector * 15

local RAYCAST = workspace:Raycast(ORIGIN, DIRECTION)

-- Unit raycast
local ORIGIN = -- set origin to the npcs primary part
local TARGET = -- set target to the closest players humanoid root part
local DIRECTION = (TARGET.Position - ORIGIN.Position).Unit * 4500

local RAYCAST = workspace:Raycast(ORIGIN, DIRECTION)

There are instances called PathfindingModifiers,

Putting them under parts, and then using their Label property to name it whatever, will essentially create a “region”.

Then, In your code, when you create a path, you can assign the costs of the labels. I believe it’d be something like:

local PATHFINDING_SERVICE = game:GetService("PathfindingService")

local MyPath = PATHFINDING_SERVICE:CreatePath({
    Costs = {
        MyLabelFromEarlier = math.huge,
    }
})

I’ll link you to the documentation on PathfindingModifiers, incase I’m incorrect.