I am trying to make an enemy AI with SimplePath, but the AI keeps getting stuck on a table and figure out how to move off of it. I included my code below. When the bot gets stuck it constantly resets its waypoint and tries to find a new one because it is stuck and can’t figure out how to walk off the table. Help appreciated, thanks.
-- Path:Run(desintaion) is how you move the bot with the SimplePath module.
local function walkToWaypoint() -- function to walk to a random destination throughout the map
Path:Run(waypoint)
local function resetWaypoint()
firstIteration = true
waypoint = workspace.aiWaypoints:GetChildren()[math.random(#workspace.aiWaypoints:GetChildren())]
end
if firstIteration == true then
firstIteration = false
Path.Reached:Connect(function()
resetWaypoint()
end)
Path.Blocked:Connect(function()
resetWaypoint()
end)
Path.Error:Connect(function()
resetWaypoint()
end)
end
end
if target then
target = target - Vector3.new(0, 4, 0)
local distance = (ai.HumanoidRootPart.Position - target)
local lookVector = ai.HumanoidRootPart.CFrame.LookVector
local raycastResult = workspace:Raycast(ai.HumanoidRootPart.Position, target - ai.HumanoidRootPart.Position,raycastParams)
visualizeRaycast(raycastResult)
if raycastResult then -- increase raycast radius to fix
if raycastResult.Instance.Parent == player.Character then
ai.Humanoid:MoveTo(target)
task.wait()
elseif player.Character.Crouching.IsCrouching.Value == false then
Path:Run(target)
else
walkToWaypoint()
end
elseif player.Character.Crouching.IsCrouching.Value == false then
Path:Run(target)
else
walkToWaypoint()
end
else
walkToWaypoint()
end