just whipped up a pathfinding system, it finds the nearest character fine but is this simplepaths issue where the ai doesnt make any attempt to decrease elevation and would much rather go a long way around?
this is using → Getting Started - SimplePath
or the devform → SimplePath - Pathfinding Module
-- // Pathfinding
--------------------------------------------------
local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection
function followPath(Target)
-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(SCP_ROOT.Position - Vector3.new(0, SCP_ROOT.Size.Y/0.75, 0), Target)
end)
if success and path.Status == Enum.PathStatus.Success then
-- Get the path waypoints
waypoints = path:GetWaypoints()
-- Detect if path becomes blocked
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex >= nextWaypointIndex then
-- Stop detecting path blockage until path is re-computed
blockedConnection:Disconnect()
-- Call function to re-compute new path
followPath(Target)
end
end)
-- Detect when movement to next waypoint is complete
if not reachedConnection then
reachedConnection = SCP:FindFirstChild(`Humanoid`).MoveToFinished:Connect(function(reached)
if reached and nextWaypointIndex < #waypoints then
-- Increase waypoint index and move to next waypoint
nextWaypointIndex += 1
SCP:FindFirstChild(`Humanoid`):MoveTo(waypoints[nextWaypointIndex].Position)
else
reachedConnection:Disconnect()
blockedConnection:Disconnect()
end
end)
end
-- Initially move to second waypoint (first waypoint is path start; skip it)
nextWaypointIndex = 2
SCP:FindFirstChild(`Humanoid`):MoveTo(waypoints[nextWaypointIndex].Position)
else
warn("Path not computed!", errorMessage)
end
end
-- // Update target [ VNU ]
RunService.Heartbeat:Connect(function()
local TargetCh = NearestCharacter()
local Pos = TargetCh.PrimaryPart.Position
followPath(Pos)
end)
--------------------------------------------------
Note to anyone who does want to look into this I have got both scripts still saved.
If you have even the slightest elevation your agent will be required to be able to jump so it can traverse those sections.
If you have areas where you absolutely do not want it to traverse (like over an upstairs railing) then you’d use pathfinding modifiers to solve that.