Is there a way to have a pathfinding NPC go around humanoids?

I have a pathfinding ship with a humanoid that needs to be able to go around planets,suns, and other ships. but I noticed that while they do avoid basic barriers. they wont go around other humanoids but will try to go straight through. this is a problem for two main reasons.

1: the planets are humanoids themselves, so a ship will try to go through it rather than around.
2: the planets are also colonizable, so when a ship comes into contact with the planet it may unintentionally land in it.

here is my pathfinding script:

local PathfindingService = game:GetService("PathfindingService")
local ship = script.Parent.Parent.Parent
local humanoid = ship.Humanoid
local goal = script.Parent
local path = PathfindingService:CreatePath()
local waypoints
local currentWaypointIndex
 local showpoints = false --if true shows the waypoints.
local waypointcontainer = Instance.new("Model")
local cleanpoints = false







function FollowPath(goal)
    path:ComputeAsync(ship.HumanoidRootPart.Position, goal.Value)
    waypoints = {}

    if path.Status == Enum.PathStatus.Success then
        waypoints = path:GetWaypoints()
        currentWaypointIndex = 1
        humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
    else
        humanoid:MoveTo(ship.HumanoidRootPart.Position)
        cleanpoints = true
    end
end




function onWaypointReached(reached)
    if reached and currentWaypointIndex < #waypoints then
        currentWaypointIndex = currentWaypointIndex + 1
        humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
    elseif reached and waypointcontainer and currentWaypointIndex == #waypoints then
        cleanpoints = true
    end
end


function showwaypoints()
    spawn(function()
    waypointcontainer.Parent = game.Workspace
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
    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
    part.Anchored = true
    part.CanCollide = false
    part.Parent = waypointcontainer
end
repeat
    wait()
until
cleanpoints == true
if cleanpoints == true then
    waypointcontainer:Destroy()
    cleanpoints = false
    waypointcontainer = Instance.new("Model")
end
end)
end





humanoid.MoveToFinished:Connect(onWaypointReached)



script.Parent.Changed:Connect(function()
    if script.Parent.Value ~= Vector3.new(0,0,0) then
FollowPath(goal)
if showpoints == true then
showwaypoints()
end
end
end)

is there something I can do to have other humanoids be treated like any other blocked barrier?

3 Likes

You could try using the Path.blocked function (link: https://developer.roblox.com/en-us/api-reference/event/Path/Blocked) to make it so that the NPC recognize the planet as a barrier and goes around it.
Hope I could help! Pathfinding isn’t really my thing but I think this could be a solution.

2 Likes

I went to your link and it looks interesting, but I dont see any descriptions or examples, could you or someone tell me how I can implement this and use it like you said?

Here there are examples on how to use it, it’s on the bottom of the page, hope I helped!

so I used the pathfinding method on that page, and with normal non humanoid objects it does recompute its path when blocked. but it still unfortunately tries to go through humanoids as if its not there.