Hello, I am currently using the “SimplePath” Pathfinding module for zombies in an upcoming zombie game I am working on and the module doesn’t work as intended.
Sometimes the Zombies go back and forth, or always try to chose the shortest possible path that doesn’t work leading to them getting stuck.
The Zombies are being controlled in a ServerScript in ServerScript Service.
I store the spawned zombies in a table and the code I am using to go to the player is below:
function GoTo(Object)
if Object ~= nil then
-- print(Object)
if Object:FindFirstChild("Humanoid") then
if Object:FindFirstChild("Humanoid").Health > 0 then
local nearestPlayer, nearestDistance
local Targets = Characters:GetChildren()
local Path
local Blocked
for i = 1, #Targets do
if Targets[i].ClassName == "Model" then
if Targets[i]:FindFirstChild("CharacterFolder") then
if Players:FindFirstChild(Targets[i].Name) then
if Targets[i].CharacterFolder:FindFirstChild("Values"):FindFirstChild("Downed").Value == false and not Targets[i]:FindFirstChild("IsZombie") then
local distance = (Object.PrimaryPart.Position.Magnitude - Targets[i].PrimaryPart.Position.Magnitude)--Zombie.PrimaryPart:DistanceFromCharacter(Targets[i].PrimaryPart.Position)
local character = Targets[i]
if not character or
distance > Range or
(nearestDistance and distance >= nearestDistance)
then
continue
end
nearestDistance = distance
nearestPlayer = Targets[i].PrimaryPart
if Players:FindFirstChild(Targets[i].Name) then
Path = SimplePath.new(Object)
--Path.Visualize = true
Path._settings.JUMP_WHEN_STUCK = true
Path:Run(Targets[i].PrimaryPart)
if Path._status == "Idle" then
warn("IDLE")
Path._humanoid.Jump = true
Path:Run(Targets[i].PrimaryPart)
elseif Path._status == "Blocked" then
warn("BLOCKED")
Path._humanoid.Jump = true
Path:Run(Targets[i].PrimaryPart)
end
if Path._events.Error or Path._events.Stopped or Path._events.Blocked then
Path:Run(Targets[i].PrimaryPart)
end
end
end
end
end
end
end
end
end
end
end
Here is the code that runs the function
game:GetService("RunService").Heartbeat:Connect(function()
for i,v in Zombies do
task.wait(1)
GoTo(Zombies[i])
end
end)
Any help will be appreciated!