How do I make a pathfinder that detects the edges of the map / baseplate

Basically I want to make a pathfinder and put it to an npc, but this pathfinder can detect the edges of the map, to avoid falling, I already have the script done, what should I add to achieve this?

SCRIPT:

wait(0.1)
local pathFindingService = game:GetService("PathfindingService")

local path = pathFindingService:CreatePath()
path:ComputeAsync(workspace.testmy.HumanoidRootPart.Position, workspace.Goal.Position)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
	if path.Status == Enum.PathStatus.Success then
		if waypoint.Action == Enum.PathWaypointAction.Jump then
			workspace.testmy.Humanoid.Jump = true
		end
		workspace.testmy.Humanoid:MoveTo(waypoint.Position)
		workspace.testmy.Humanoid.MoveToFinished:Wait()
	else
		print("failed path")
		break
	end
end

You could utilize the new pathfinding modifiers (BETA). Otherwise, you could always just add invisible barriers around your map, and PathfindingService would have to find a way to avoid those barriers (if possible).

1 Like

Thanks, but i am sure there is another form to archieve this

locsl part = workspace.Part
local partNegEndX = part.Position.X - part.Size.X/2
local partPosEndX = part.Position.X + part.Size.X/2
local partNegEndY = part.Position.Y - part.Size.Y/2
local partPosEndY = part.Position.Y + part.Size.Y/2
local partNegEndZ = part.Position.Z - part.Size.Z/2
local partPosEndZ = part.Position.Z + part.Size.Z/2

This would get you the the boundaries of each directional component for any part.