Advertisement
SigmaBoy456

Path Roblox Test #928

Aug 28th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. local PathfindingService = game:GetService("PathfindingService")
  2. local Players = game:GetService("Players")
  3.  
  4. local player = Players.LocalPlayer
  5. local character = player.Character or player.CharacterAdded:Wait()
  6. local humanoid = character:WaitForChild("Humanoid")
  7. local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  8.  
  9. -- Target position (change this to your desired target position)
  10. local targetPosition = Vector3.new(100, 0, 100)
  11.  
  12. -- Create a path
  13. local path = PathfindingService:CreatePath({
  14. AgentRadius = 2,
  15. AgentHeight = 5,
  16. AgentCanJump = true,
  17. AgentJumpHeight = 7,
  18. AgentMaxSlope = 45,
  19. AgentCanClimb = true,
  20. })
  21.  
  22. -- Function to move to target
  23. local function moveToTarget(target)
  24. -- Compute the path to the target position
  25. path:ComputeAsync(humanoidRootPart.Position, target)
  26.  
  27. -- Check if the path was successfully computed
  28. if path.Status == Enum.PathStatus.Success then
  29. -- Get the waypoints and move the character along them
  30. local waypoints = path:GetWaypoints()
  31. for _, waypoint in ipairs(waypoints) do
  32. humanoid:MoveTo(waypoint.Position)
  33. humanoid.MoveToFinished:Wait()
  34.  
  35. -- If the waypoint requires a jump, make the character jump
  36. if waypoint.Action == Enum.PathWaypointAction.Jump then
  37. humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  38. end
  39. end
  40. else
  41. -- If the path couldn't be computed, print a message
  42. warn("Path could not be computed.")
  43. end
  44. end
  45.  
  46. -- Start moving to the target position
  47. moveToTarget(targetPosition)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement