so i have a npc and sometimes it randomly starts swimming in the ocean ( sand under the ocean ), so how would i make it so the pathfinding avoids terrain, heres the part of the script that makes it move:
function pathToLocation(location)
local path = game:GetService("PathfindingService"):CreatePath()
path:ComputeAsync(myRoot.Position,location)
local waypoints = path:GetWaypoints()
pathCount = pathCount + 1
if path.Status == Enum.PathStatus.Success then
local currentPathCount = pathCount
for i, waypoint in ipairs(waypoints) do
if currentPathCount ~= pathCount then
return
end
if waypoint.Action == Enum.PathWaypointAction.Jump then
myHuman.Jump = true
end
myHuman:MoveTo(waypoint.Position)
delay(0.5, function()
if myHuman.WalkToPoint.Y > myRoot.Position.Y then
myHuman.Jump = true
end
end)
local moveSuccess = myHuman.MoveToFinished:Wait()
if not moveSuccess then
break
end
if fleeing == true then
if i == #waypoints then
wander()
end
end
end
else
getUnstuck()
end
end