PathfindingService 는 벽이나 다른 장애물을 피하지 않고 캐릭터가 점 사이에서 이동할 수 있도록 합니다. 기본적으로 가장 짧은 경로가 계산되지만 벽이나 다른 장애물을 피하도록 경로 찾기 모드리퍼를 구현하여 다양한 재료, 정의된 영역 또는 장애물을 통해 더 지능적인
자세한 내용은 캐릭터 경로 찾기를 참조하십시오.
요약
메서드
제공된 두 점 사이에서 Class.경로찾습니다.
속성
메서드
CreatePath
다양한 에이전트 매개 변수에 따라 Path 개체를 생성합니다. agentParameters 테이블에 있는 유효한 키 및 값은 다음과 같습니다.
<tbody><tr><td><b>에이전트 라디오스</b></td><td>정수</td><td>2</td><td>공간을 횡단할 수 있는 최소 크기를 결정합니다.</td></tr><tr><td><b>에이전트 높이</b></td><td>정수</td><td>5</td><td>공간을 횡단할 수 있는 최소 크기를 결정합니다.</td></tr><tr><td><b>AgentCanJump</b></td><td>부울</td><td>참</td><td>경로 탐색 중에 점프할 수 있는지 여부를 결정합니다.</td></tr><tr><td><b>에이전트 등반 가능</b></td><td>부울</td><td>없음</td><td>경로 탐색 중에 <code>Class.TrussPart|TrussParts</code>를 클라이밍할 수 있는지 여부를 결정합니다.</td></tr><tr><td><b>방향 간격 지정</b></td><td>숫자</td><td>4</td><td>경로의 중간 지점 간의 간격을 결정합니다.</td></tr><tr><td><b>Costs</b></td><td>테이블</td><td></td><td>재료 테이블 또는 정의된 <code>Class.Pathfindingmodified|PathfindingModifiers</code> 및 이동에 대한 "비용"을 참조하십시오. 특정 재료/지역을 다른 재료/지역보다 선호하게 하려면 에 유용합니다. 자세한 내용은 <a href="../../../characters/pathfinding.md#pathfinding-modifiers">여기</a>에 참조하십시오.</td></tr></tbody>
키 | 유형 | 기본 | 설명 |
---|
매개 변수
경로 크기를 조정하려는 경로에 대한 미세 조정 기능이 있는 Lua 테이블(경로에 따라 이동하는 인간형 개체의 개체). 위에서 유효한 키, 형식 및 설명을 참조하십시오.
반환
Class.경로개체.
코드 샘플
Demonstrates creating a path using PathfindingService:CreatePath()
'PathOptions' represents a Model with three paths made of different materials. When creating the path we define a large 'Cost' for two of the three paths materials. This will ensure the path created steers towards the path with the material of the lowest 'Cost'.
Once the path is created, small parts are created at each waypoint to visualize the path.
local Workspace = game:GetService("Workspace")
local PathfindingService = game:GetService("PathfindingService")
-- This model contains a start, end and three paths between the player can walk on: Snow, Metal and LeafyGrass
local PathOptionsModel = script.Parent.PathOptions
local startPosition = PathOptionsModel.Start.Position
local finishPosition = PathOptionsModel.End.Position
-- Create a path that avoids Snow and Metal materials
-- This will ensure the path created avoids the Snow and Metal paths and guides
-- the user towards the LeafyGrass path
local path = PathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = false,
Costs = {
Snow = math.huge,
Metal = math.huge,
},
})
-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(startPosition, finishPosition)
end)
-- Confirm the computation was successful
if success and path.Status == Enum.PathStatus.Success then
-- For each waypoint, create a part to visualize the path
for _, waypoint in path:GetWaypoints() do
local part = Instance.new("Part")
part.Position = waypoint.Position
part.Size = Vector3.new(0.5, 0.5, 0.5)
part.Color = Color3.new(1, 0, 1)
part.Anchored = true
part.CanCollide = false
part.Parent = Workspace
end
else
print(`Path unable to be computed, error: {errorMessage}`)
end
FindPathAsync
이 함수는 제공된 두 점 사이에서 Path를 찾습니다. 이 경로는 PathfindingService 에서 생성한 탐색 그리드를 사용하며 정규 크기의 Roblox 캐릭터가 경로를 따라갈 수 있습니다.
이 함수는 경로의 좌표를 포함하는 Path 개체를 반환합니다. 두 점 사이에 경로가 없으면 이 함수는 Path 개체를 반환하지만, 그 개체의 Path.Status는 2> Class.Path.Status2> 이 됩니다.
Class.Path 개체의 경로를 가져오려면 Path:GetWaypoints() 함수를 사용할 수 있습니다.
매개 변수
반환
Class.경로개체.