Hey people. I just start learning about the PathFinding Service and it seems to works decently well.
So anyway i need an idea on how would i move an object using pathfinding service and move them using Lerping
I refused using Humanoid:MoveTo() or the humanoid instance itself because its very badly optimized and will slow the game if there’s too much of it.
Here is my current Code of the pathfinding:
-- temp means target's torso
local path = pathfindingservice:CreatePath()
path:ComputeAsync(root.Position,temp.Position)
if path.Status == Enum.PathStatus.Success then
local wp = path:GetWaypoints()
local ogPos = temp.Position
for i,point in pairs(wp) do
if i == 1 then
continue
end
repeat
task.wait()
until hum.FloorMaterial ~= Enum.Material.Air
hum:MoveTo(point.Position)
if temp then
if (temp.Position - ogPos).Magnitude > 10 then
break
end
else
break
end
local finished = hum.MoveToFinished:Wait()
if finished then
break
end
end
end
Is there any mistakes at my code I’d appreciate the help too!!