Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pathfinding Error when NPC tries moving through a Union?

Asked by 6 years ago
Edited 1 year ago

So I'm trying to make an NPC walk to a point using pathfinding, but then I noticed I would get an error if the NPC is trying to walk through a union. The union is a room with an entrance created by a NegatePart, and it lets me walk through it. I think my script though thinks my room is completely blocked off and ignores the entrance.

What I need help on is how to make my script ignore the union, or walk through the entrance with no problem.

If you want to look at the script I'm using for pathfinding, here it is :

while wait(1) do
path = game:GetService('PathfindingService'):FindPathAsync(script.Parent.HumanoidRootPart.Position, game.Workspace.NPCEscapePart.Position)
if path.Status == Enum.PathStatus.Success then
    print('Success!')
else
    script.Parent.Humanoid.WalkToPoint = Vector3.new(-89, 1.5, 0) --Directly set WalkToPoint when pathfinding won't work
    warn('Error! Cannot find valid path for NPC.')
end
local points = path:GetWaypoints()

    for i = 2, #points do
        local waypoint = points[i]
        local dest = waypoint.Position
        script.Parent.Humanoid:MoveTo(dest)
        if waypoint.Action == Enum.PathWaypointAction.Jump then
            script.Parent.Humanoid.Jump = true
        end
        local reached = script.Parent.Humanoid.MoveToFinished:Wait()
        if not reached then
            break
        end
    end
end

This script works fine until it has to deal with unions. I don't know much about pathfinding too so sorry if this script is a little basic.

I also thought of 2 solutions to fix this, to directly set the WalkToPoint property in the NPC's humanoid to the part's position, or make several parts and also directly set the WalkToPoint property to the parts, and set the WalkToPoint to the next part once the NPC touches the part.

I then thought of some problems with the solutions. The NPC might get stuck somewhere as there's no pathfinding when I set the WalkToPoint, and I'm planning to make a place with lots of hallways and doors and corridors and etc, so making all the parts and setting the WalkToPoints is going to be painful to do.

1
Fix number 2 will probably be the only way to rectify this. Technically, an union ( why does "an" sound wrong here?) is handled as one solid part by everything but visual rendering and physics rendering, . So I think if you use pathfinding to move in front of the corridor, then manually make it walk through, them resume path finding service. protectiveebob 221 — 6y
0
So there’s no way for Pathfinding to ignore a Union? If so, guess I’ll have to start setting up the parts. Thanks for helping. (And also I don’t know why “an” sounds wrong there) User#20279 0 — 6y

Answer this question