Pathfinding agent don't want to fall from edge

I am trying to create a pathfinding ai for zombies my game. I encountered a problem that agent don’t want to fall down even from short height
Here is some videos


That is code for pathfinding

local pathFindService = game:GetService("PathfindingService")
local players = game:GetService("Players")
local RunService = game:GetService("RunService")


function getNearestPlayer()
	local referencePoint = workspace.BasePlate
	local nearestPlayer = nil
	local nearestDistance = math.huge
	for _, player in pairs(players:GetChildren()) do
		local character = player.Character
		if character then
			local distance = (character.HumanoidRootPart.Position - referencePoint.Position).Magnitude
			if distance < nearestDistance then
				nearestDistance = distance
				nearestPlayer = player
			end
		end
	end
	return nearestPlayer,nearestDistance
end


local zombie = {}
	
zombie.__index = zombie

function zombie.Create(ZombieStats)

	local newZombie = {}
	newZombie.Character = ZombieStats.model:Clone()
	newZombie.Health = ZombieStats.health
	newZombie.Character.Humanoid.Health = ZombieStats.health
	newZombie.Character.Humanoid.MaxHealth = ZombieStats.health
	newZombie.WalkSpeed = ZombieStats.walkSpeed
	newZombie.Character.Humanoid.WalkSpeed = ZombieStats.walkSpeed
	newZombie.Range = ZombieStats.range
	newZombie.Damage = ZombieStats.damage
	
	
	newZombie.Target = nil
	
	
	task.spawn(function()
		newZombie.Character["Body Colors"].HeadColor3 = Color3.new(0,newZombie.Character["Body Colors"].HeadColor3.G-ZombieStats.colorChange,0)
		newZombie.Character["Body Colors"].LeftArmColor3 = Color3.new(0,newZombie.Character["Body Colors"].LeftArmColor3.G-ZombieStats.colorChange,0)
		newZombie.Character["Body Colors"].RightArmColor3 = Color3.new(0,newZombie.Character["Body Colors"].RightArmColor3.G-ZombieStats.colorChange,0)
	end)
	newZombie.Character.Parent = workspace.Zombies
	newZombie.Character.HumanoidRootPart.CFrame = ZombieStats.spawnPoint.CFrame
	
	task.spawn(function()
		local walkTrack = newZombie.Character.Humanoid.Animator:LoadAnimation(game:GetService("ReplicatedStorage").Animations.Zombie.Walk)
		walkTrack.Looped = true
		RunService.Heartbeat:Connect(function()

			if newZombie.Character.Humanoid.WalkToPoint ~= Vector3.new(0,0,0) then
				if not walkTrack.IsPlaying then
					walkTrack:Play()
				end
			end

		end)
	end)



	setmetatable(newZombie,zombie)
	return newZombie

end

function zombie:Attack()
	
	if self.Character:GetAttribute("debounce") then
		return
	end
	self.Character:SetAttribute("debounce",true)
	
	local attackTrack = self.Character.Humanoid.Animator:LoadAnimation(game:GetService("ReplicatedStorage").Animations.Zombie.Attack)
	attackTrack:Play()
	local direction = self.Character.HumanoidRootPart.CFrame.LookVector
	local origin = self.Character.HumanoidRootPart.Position
	
	local rayCastParams = RaycastParams.new()
	rayCastParams.FilterType = Enum.RaycastFilterType.Exclude
	rayCastParams.FilterDescendantsInstances = {self.Character}
	
	local rayCastResult = workspace:Raycast(origin,direction*5,rayCastParams)

	if rayCastResult and rayCastResult.Instance.Parent:FindFirstChild("Humanoid") then

		local hitPart = rayCastResult.Instance
		local humanoid = hitPart.Parent.Humanoid
		if humanoid then
			task.spawn(function()

				task.wait(1)
				self.Character:SetAttribute("debounce",false)
			end)
			if string.find(humanoid.Parent.Name,"Zombie") then
				humanoid:TakeDamage(1)
			else
				humanoid:TakeDamage(self.Damage)
			end
		end
	end
	
end

function zombie:Move()
	if self.Target then
		if (self.Character.HumanoidRootPart.Position-self.Target.HumanoidRootPart.Position).Magnitude > self.Range then
			pcall(function()
				local pathParams = {
					AgentCanClimb = true,
					AgentCanJump = true,
					WaypointSpacing = 20
				}

				local path = pathFindService:CreatePath(pathParams)
				path:ComputeAsync(self.Character.HumanoidRootPart.Position,self.Target.HumanoidRootPart.Position)
				local Waypoints = path:GetWaypoints()

				for _,waypoint in pairs(Waypoints) do
					if Waypoints and Waypoints[2] then
						local data = Waypoints[2]
						if data.Action == Enum.PathWaypointAction.Jump then
							self.Character.Humanoid.Jump = true
						elseif waypoint.Action == Enum.PathWaypointAction.Jump then
							self.Character.Humanoid.Jump = true
						end
						self.Character.Humanoid:MoveTo(data.Position)
					end
				end
			end)

		else
			self:Attack()
		end
	end
end



function zombie:FindTarget()
	
	local findTargetTread
	
	findTargetTread = RunService.Heartbeat:Connect(function()
		
		self.Character.Humanoid.Died:Connect(function()
			findTargetTread:Disconnect()
			return
		end)
		
		local nearestPlayer,distance = getNearestPlayer()
		self.Target = nearestPlayer.Character
		self:Move()
	end)
	
end

return zombie

I alredy tryed to change pathfindingParams but it doesnot work

Go to humanoid and enable autojumpenabled.

It is already enabled and does not work

Here’s a few easy things you can try:

  1. Turning CanJump to true in pathfinding modifiers
  2. Increasing the hip height of the humanoid
  3. Enabling the more advanced pathfinding feature in workspace
  4. Using Pathfinding modifiers to make pathfinding detect the part as a ramp

Full detail of how you should setup your map base on your needs

1 Like