Path

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
복제되지 않음

경로 개체는 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.

요약

메서드

이벤트

속성

읽기 전용
복제되지 않음
병렬 읽기

메서드

GetWaypoints


반환

코드 샘플

Get Path Waypoints

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

CheckOcclusionAsync

생성

매개 변수

start: number
기본값: ""

반환

ComputeAsync

()
생성

매개 변수

start: Vector3
기본값: ""
finish: Vector3
기본값: ""

반환

()

코드 샘플

Using the Pathfinding Service

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)

이벤트

Blocked

매개 변수

blockedWaypointIdx: number

Unblocked

매개 변수

unblockedWaypointIdx: number