I've been working with PathFinding. Currently, my function can calculate and move an NPC appropriately to the required location.
Here's my problem: Say the path between the NPC and the destination is completely blocked. The NPC will compute a path that stops as close as it can to the blockage, which is fine. If the blockage is moved/rotated in the environment and a path is opened, it will move accordingly to it. The problem is if the blockage is deleted from the workspace, then the NPC behave as if the path is still blocked until one of two things occur.
1. I move the destination location in runtime (only if I'm using a object rather than a static position)
2. If a PathFind brick creator script is running (see func 2 below)
Sidenote: The Path Status is ClosestOutOfRange while the Path is blocked, which is technically correct. But it continues to be this when the path is unblocked and only changes to Successwhen one of those two events occur.
Here's my PathFinding Function
I'm indexing an object when calling this function, rather than the secondary option of a position.
function PathFind(object, position)
local location = nil --Pos pathfind wont upate yet, usage not reccomended
local pos = true
if not object then location = position else location = object.Position pos = false end
while (Human.Torso.Position - location).magnitude > 5 do
if not pos then location = object.Position end
local path = game:GetService("PathfindingService"):ComputeRawPathAsync(Human.Torso.Position, location, 200)
local points = path:GetPointCoordinates()
print(path.Status)
--repeat wait() print(path.Status) commented out because it does nothing useful
--until ComputePath(Human.Torso.Position, location, 200).Status == Enum.PathStatus.Success or points[2]
pcall(function() Humanoid:MoveTo(points[2]) end)
wait()
end
end
Here's the script of event 2 that causes the NPC's to continue behaving properly when a blockage is deleted.
I believe it's the ROBLOX example of PathFinding, or close to it. It simply places bricks in points of a path, I have it set up for a specific NPC.
while true do
endpath = workspace.Part.Position
path = game:GetService ("PathfindingService"):ComputeRawPathAsync (game.Workspace.Figure3.Torso.Position,endpath,200)
points = path:GetPointCoordinates()
game.Workspace.Points:ClearAllChildren()
for p = 1, #points do
part = Instance.new("Part")
part.FormFactor = Enum.FormFactor.Symmetric
part.Size = Vector3.new(1,1,1)
part.CanCollide = false
part.Position = points[p]
part.Anchored = true
part.BrickColor = BrickColor.DarkGray()
part.Parent = game.Workspace.Points
end
wait(0.5)
end
Any help is greatly appreciated. I've been racking my brain all day trying to figure out what's wrong and it just doesn't make sense to me. Hopefully one of you will find my error. Thanks!
