Pathfinding on a moving part?

Hello!

Simple question, is it possible to make a pathfinding NPC work on a moving part? I have a spinner for my obby’s tutorial and want to know if I can automatically have it pathfind or if I need to make my own path with :MoveTo and calculate magnitudes and whatnot?

1 Like

It is possible to make a pathfinding NCP work on a moving; however, it will be even greater to make your own path. According to my beliefs.

So I should just create my own path and use :MoveTo and calculate the distance from the moving part to the NPC?

1 Like

It is, actually. You can use a while loop for it so it constantly finds the part. To get the npc to move towards to moving part do

local wps = path:GetWaypoints()
npc.Humanoid.WalkToPart = wps[#wps].Position

Then you can have it delete the OLD table of parts to reduce lag.
Outside of the loop do

local old == nil

Then inside the while loop something like:

 local wps = path:GetWaypoints()
npc.Humanoid.WalkToPart = wps[#wps].Position
if old == nil then
for i,v in pairs(old) do v:Destroy() end
old = wps
elseif old ~= nil then
old = wps
end
3 Likes