trying to get my npc to walk up this tiny ledge but its getting stuck, i dont wanna use jump since it’d look weird if it had to jump just to get over the smallest obstacle. I want the npc to just go up it like players do
Code:
local rootPart = newMob.PrimaryPart
local hum = newMob:WaitForChild("Humanoid")
local mobInfo = MobIndex[mobModel.Name]
self.mob = newMob
self.mobInfo = mobInfo
local path : Path = pathServ:CreatePath(mobInfo.Pathfinding)
local targetPart = workspace.PathPart
local waypoints
local nextWaypoint
local reachedConnection
local blockedConnection
local recalcConnection
local function followPath()
local success, errMsg = pcall(function()
--local targetPos = Vector3.new(targetPart.Position.X, rootPart.Position.Y, targetPart.Position.Z)
path:ComputeAsync(rootPart.Position, targetPart.Position)
end)
if success and path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for i, waypoint : PathWaypoint in ipairs(waypoints) do
if i == 1 then continue end
if blockedConnection then
blockedConnection:Disconnect()
blockedConnection = nil
end
if reachedConnection then
reachedConnection:Disconnect()
reachedConnection = nil
end
if recalcConnection then
recalcConnection:Disconnect()
recalcConnection = nil
end
hum:MoveTo(waypoint.Position)
local recalc = false
local pathReached = false
blockedConnection = path.Blocked:Connect(function()
recalcConnection:Disconnect()
reachedConnection:Disconnect()
recalc = true
end)
recalcConnection = RunServ.Heartbeat:Connect(function()
if (waypoints[#waypoints].Position - targetPart.Position).Magnitude > 5 then
print("recalc")
recalcConnection:Disconnect()
reachedConnection:Disconnect()
recalc = true
end
end)
reachedConnection = hum.MoveToFinished:Connect(function()
reachedConnection:Disconnect()
recalcConnection:Disconnect()
pathReached = true
end)
repeat task.wait() until recalc == true or pathReached == true
if recalc then return end
end
elseif errMsg then
warn("Path not computed: "..errMsg)
end
end
while task.wait() do
if (rootPart.Position - targetPart.Position).Magnitude > 5 then
print("follow")
followPath()
end
end