Hello, I am working on path finding for a zombie AI and it seems that when the zombie is spawned in the game and you are behind a cancollided wall he will create a path. He will find you in the players and label you a target, but he can’t create a path to you, but no errors pop up. It seems as if it is just a bug that I don’t know how to fix. I was wondering if there was a way to fix this, or to check to see if a path was created, and if it wasn’t created maybe he can be deleted from the workspace and respawned somewhere else.
I am not quite sure how to check if a path was created. Could anyone give me some pointers?
Below I have posted a picture that I will explain.
Here is my code:
function findPath(target)
showImage()
local path = game:GetService("PathfindingService"):CreatePath()
path:ComputeAsync(myRoot.Position,target.Position)
local waypoints = path:GetWaypoints()
local success = path.Status == Enum.PathStatus.Success
if success then
for _, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
myHuman.Jump = true
end
myHuman:MoveTo(waypoint.Position)
local timeOut = myHuman.MoveToFinished:Wait(1)
if not timeOut then
myHuman.Jump = true
print("Path too long!")
findPath(target)
break
end
if checkSight(target) then
repeat
--print("Moving directly to the target")
myHuman:MoveTo(target.Position)
attack(target)
wait(0.1)
if target == nil then
break
elseif target.Parent == nil then
break
end
until checkSight(target) == false or myHuman.Health < 1 or target.Parent.Humanoid.Health < 1
break
end
if (myRoot.Position - waypoints[1].Position).magnitude > 20 then
print("Target has moved, generating new path")
findPath(target)
break
end
end
end
end
This picture is taken during a test play and I am in the server view.
In this picture on the left you can see a zombie that has found a path because it is playing the moving animation. On the right you can see the same type of zombies that could not find a path and are not moving. My character is behind that black wall on the right.