My current goal is to detect if the character gets blocked faster than the simple timeout that comes with humanoid MoveTo.
I’m currently using:
local timeOut = plrHumanoid.MoveToFinished:Wait()
if not timeOut
return "Blocked"
end
However, The timeout for humanoid is 8 seconds and that is far too long.
I’ve tried:
.Blocked, but it never fires on the path object.
Magnitude is too unreliable due to object thickness
Raycasting never fires upon actual blocks, and random triggers during jumps.
I’m hoping by posting this someone can point me in the right direction.
The current function I use for moving the NPC:
function pathFind:moveNPC(plrHum, pathObject)
local pathTable = pathObject:GetWaypoints()
for i, point in pairs(pathTable) do
if point.Action == Enum.PathWaypointAction.Jump then
plrHum:ChangeState(Enum.HumanoidStateType.Jumping)
end
plrHum:MoveTo(point.Position)
local timeOut = plrHum.MoveToFinished:Wait()
if not timeOut then
return {status = 0}
end
end
return {status = 1}
end
I’ve tried asking other developer friends, but they seem to be just as stumped as I am. Thank you ahead of time for any advice you guys can give me.
Waiting less than the hard-coded 8 seconds (How much less? Max 3 seconds?)
Or when MoveToFinished is fired, as long it happens before the “waiting less than”
Perhaps using a BindableEvent can be a work-around? One that will be fired by a MoveToFinished:Connect() or a “waiting less than 8 seconds”-delayed-function.
The below code has not been tested, so I do not know if it actually works or not!
local function moveNPC(plrHum, pathObject)
local pathTable = pathObject:GetWaypoints()
for i, point in pairs(pathTable) do
if point.Action == Enum.PathWaypointAction.Jump then
plrHum:ChangeState(Enum.HumanoidStateType.Jumping)
end
local evt = Instance.new("BindableEvent")
delay(3, function() if evt then evt:Fire("Timeout") end end)
plrHum.MoveToFinished:Connect(function() if evt then evt:Fire("Finished") end end)
plrHum:MoveTo(point.Position)
local result = evt.Event:Wait()
evt:Destroy() -- Important to "clean up"
evt = nil -- Equally important, for attempting to not cause the anonymous functions error
if result == "Timeout" then
return {status = 0}
end
end
return {status = 1}
end
You can try and see if there is ever something blocking a few raycasts between nodes (and from the NPC to the current node), making it slightly above floor level, and along some of the upcoming nodes if you want them to see ahead.