PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetWaypoints

This function returns an array of all the DataType/PathWaypoint|PathWaypoints in a Path, as computed by Path/ComputeAsync.

Each waypoint in the array specifies a DataType/Vector3 position and Enum/PathWaypointAction|action to take when this PathWaypoint is reached. The array is arranged in the order of waypoints from the path start to path end.

If a path could not be computed, this function will return an empty array.

Returns

Return Type Summary

An array of DataType/PathWaypoint|PathWaypoints ordered from path start to path end


Code Samples


Get Path Waypoints

The example below demonstrates how to create a Path and it’s DataType/PathWaypoint|PathWaypoints using the PathService.

It tries to PathService/ComputeAsyc a path between two DataType/Vector3 positions, from pathStart to pathEnd. If a path is successfully created, indicated by it’s Enum/PathStatus, the code block gets an array of its waypoints using PathService/GetWaypoints. Then, it loops through the array and prints each waypoint’s position.

local PathfindingService = game:GetService("PathfindingService")

-- Create path object
local path = PathfindingService:CreatePath()

local pathStart = Vector3.new(0, 1, 0)
local pathEnd = Vector3.new(100, 1, 25)

-- Compute and check the path
path:ComputeAsync(pathStart, pathEnd)

if path.Status == Enum.PathStatus.Success then
	-- Get path waypoints
	local waypoints = path:GetWaypoints()
	-- Loop through waypoints
	for _, waypoint in pairs(waypoints) do
		-- Output position of waypoint
		print(waypoint.Position)
	end
end