I’m trying to create a zombie that follows the person, but I’m not getting it, see the video:
The zombie until it follows the player, but it stops when, apparently, it does not find a way to Player.
Another problem is that when the zombie misses the jump (as shown in the video) it just doesn’t try again until it succeeds
here’s my script:
local PathFinderService = game:GetService("PathfindingService")
local path = PathFinderService:CreatePath()
local humanoid = script.Parent:FindFirstChild("Humanoid")
local body = script.Parent:FindFirstChild("HumanoidRootPart")
function FindNearestPlayer (pos)
local list = game.Workspace:GetChildren()
local humRoot = nil
local distance = 200
local temp1 = nil
local temp2 = nil
local human = nil
for x = 1,#list do
temp2 = list[x]
if temp2:IsA("Model") and temp2 ~= script.Parent then
temp1 = temp2:FindFirstChild("HumanoidRootPart")
human = temp2:FindFirstChild("Humanoid")
if human ~= nil and temp1 ~= nil and human.Health > 0 then
if (temp1.Position - pos).Magnitude < distance then
humRoot = temp1
distance = (temp1.Position - pos).Magnitude
end
end
end
end
return humRoot
end
while true do
local dest = FindNearestPlayer(script.Parent.HumanoidRootPart.Position)
if dest ~= nil then
path:ComputeAsync(script.Parent.HumanoidRootPart.Position,dest.Position)
local WayPoints = path:GetWaypoints()
for _,Waypoint in pairs (WayPoints) do
humanoid:MoveTo(Waypoint.Position)
if Waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
wait(0.1)
end
end
wait(0.1)
end
does anyone know how to improve this and some tips to make the movement more natural (as if it were not a walking robot)?