Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PathfindingService = game:GetService("PathfindingService")
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- -- Target position (change this to your desired target position)
- local targetPosition = Vector3.new(100, 0, 100)
- -- Create a path
- local path = PathfindingService:CreatePath({
- AgentRadius = 2,
- AgentHeight = 5,
- AgentCanJump = true,
- AgentJumpHeight = 7,
- AgentMaxSlope = 45,
- AgentCanClimb = true,
- })
- -- Function to move to target
- local function moveToTarget(target)
- -- Compute the path to the target position
- path:ComputeAsync(humanoidRootPart.Position, target)
- -- Check if the path was successfully computed
- if path.Status == Enum.PathStatus.Success then
- -- Get the waypoints and move the character along them
- local waypoints = path:GetWaypoints()
- for _, waypoint in ipairs(waypoints) do
- humanoid:MoveTo(waypoint.Position)
- humanoid.MoveToFinished:Wait()
- -- If the waypoint requires a jump, make the character jump
- if waypoint.Action == Enum.PathWaypointAction.Jump then
- humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
- end
- end
- else
- -- If the path couldn't be computed, print a message
- warn("Path could not be computed.")
- end
- end
- -- Start moving to the target position
- moveToTarget(targetPosition)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement