경로 개체는 PathfindingService:CreatePath() 생성된 경로의 결과를 저장합니다.
경로 개체가 생성되면 시작 지점과 종점을 사용하여 Path:ComputeAsync()를 호출할 수 있습니다.이는 기본 또는 사용자 지정 매개 변수를 통해 전달된 경로에 따라 캐릭터가 이동할 수 있는 유효한 경로를 계산하려고 시도합니다, CreatePath() .경로를 성공적으로 찾으면 개체에는 값의 가 있습니다.그렇지 않으면 상태가 Enum.PathStatus.NoPath 이 될 수 있으며, 두 지점 사이에 장애물이 있거나 지점이 단단한 개체 내에 있을 경우 발생할 수 있습니다.
ComputeAsync() 에 더해, Path 개체에는 경로의 시작부터 끝까지 캐릭터가 따라야 하는 지점을 나타내는 목록을 반환하는 GetWaypoints() 메서드가 있습니다.
마지막으로, Path 개체는 연결될 수 있습니다 이벤트에 대해 Path.Blocked 에 연결될 수 있습니다.이 이벤트는 경로가 존재하는 동안 언제든지 경로가 차단되면 발생합니다.이는 경로를 따라 이동하는 문자 뒤에서만 발생할 수 있으며, 앞에서만 발생하지는 않습니다. Note that this can occur behind a character moving along the path, not just in front of it.
요약
메서드
경로에서 포인트 배열을 반환합니다.
특정 웨이포인트부터 경로가 차단되는지 확인합니다.
시작 위치에서 끝 위치까지 Path 를 계산합니다.
이벤트
계산된 경로가 차단되면 발생합니다.
차단되었던 계산된 경로가 차단 해제되면 발생합니다.
속성
Status
메서드
GetWaypoints
반환
코드 샘플
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
local PATH_START = Vector3.new(0, 1, 0)
local PATH_END = Vector3.new(100, 1, 25)
path:ComputeAsync(PATH_START, PATH_END)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
print(waypoint.Position)
end
end
ComputeAsync
매개 변수
반환
코드 샘플
local PathfindingService = game:GetService("PathfindingService")
local agentParams = {
AgentRadius = 2.0,
AgentHeight = 5.0,
AgentCanJump = false,
}
local currentWaypointIdx = 1
local path = PathfindingService:CreatePath(agentParams)
local humanoidRootPart = script.Parent:FindFirstChild("HumanoidRootPart")
local targetPosition = Vector3.new(50, 0, 50)
path:ComputeAsync(humanoidRootPart.Position, targetPosition)
-- When the path is blocked...
local function OnPathBlocked(blockedWaypointIdx)
-- Check if the obstacle is further down the path
if blockedWaypointIdx > currentWaypointIdx then
-- Recompute the path
path:ComputeAsync(humanoidRootPart.Position, targetPosition)
if path.Status == Enum.PathStatus.Success then
-- Retrieve update waypoint list with path:GetWaypoints()
-- and Continue walking towards target
else
-- Error, path not found
end
end
end
path.Blocked:Connect(OnPathBlocked)