Advertisement
SpacecowboyHX

Walk to point in roblox with AI Pathfinding

Mar 16th, 2020
2,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. local serv = game:GetService("PathfindingService")
  2. local human = script.Parent:WaitForChild("Humanoid")
  3. local body = script.Parent:FindFirstChild("Torso") or script.Parent:FindFirstChild("HumanoidRootPart")
  4. local dest = workspace:FindFirstChild("Spot")
  5. local path = serv:CreatePath()
  6. path:ComputeAsync(body.Position,dest.Position)
  7. if path.Status == Enum.PathStatus.Success then
  8.     local wayPoints = path:GetWaypoints()
  9.     for i = 1,#wayPoints do
  10.         local point = wayPoints[i]
  11.         human:MoveTo(point.Position)
  12.         local success = human.MoveToFinished:Wait()
  13.         if point.Action == Enum.PathWaypointAction.Jump then
  14.             human.WalkSpeed = 0
  15.             wait(0.2)
  16.             human.WalkSpeed = 16
  17.             human.Jump = true
  18.         end
  19.         if not success then
  20.             print("trying again")
  21.             human.Jump = true
  22.             human:MoveTo(point.Position)
  23.             if not human.MoveToFinished:Wait() then
  24.                 break
  25.             end
  26.         end
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement