I’ve made a script from a tutorial how to make zombie chasing the player and damaging them, but I want to make them not stuck on the wall or obstacles like making them dodge or jump over them, here is what I made:
local zombie = script.Parent
local humanoid = zombie:WaitForChild("Humanoid")
zombie.PrimaryPart:SetNetworkOwner(nil)
local attackDebounce = false
local function Chase()
local players = game.Players:GetPlayers()
local maxDistance = 100
local nearestTarget = nil
for i, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (zombie.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end
local function Attack(target)
local distance = (zombie.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance > 2.5 then
humanoid:MoveTo(target.HumanoidRootPart.Position)
else
if attackDebounce == false then
attackDebounce = true
target.Humanoid:TakeDamage(10)
wait(0.5)
attackDebounce = false
end
end
end
while wait() do
local target = Chase()
if target then
humanoid:MoveTo(target.HumanoidRootPart.Position)
Attack(target) -- Damage the target
end
end
I put the PathfindingService on the chase function, but they still run to the wall and don’t jump over the obstacles
local function Chase()
local players = game.Players:GetPlayers()
local maxDistance = 100
local nearestTarget = nil
local path = pathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = true
})
for i, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (zombie.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
local success, errorMessage = pcall(function()
path:ComputeAsync(zombie.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
end)
if success and path.Status == Enum.PathStatus.Success then
if distance < maxDistance then
nearestTarget = target
maxDistance = distance
end
else
warn("Path not computed!", errorMessage)
end
end
end
return nearestTarget
end