경로 찾기 서비스 는 두 지점 사이의 논리적 경로를 찾아 캐릭터가 벽이나 다른 장애물에 부딪히지 않고 지점 사이를 이동할 수 있도록 합니다.기본적으로 가장 짧은 경로가 계산되지만, 정의된 영역이나 장애물을 통해 다양한 재료에서 더 똑똑한 경로를 계산하기 위한 경로 찾기 수정자를 구현할 수 있습니다.
사용 세부 정보는 문자 경로 찾기에 참조하십시오.
요약
메서드
제공된 두 점 사이에서 Path를 찾습니다.
속성
메서드
CreatePath
다양한 에이전트 매개 변수에 따라 Path 개체를 생성합니다. agentParameters 테이블의 유효한 키와 값은 다음과 같습니다:
<th>유형</th><th>기본</th><th>설명</th></tr></thead><tbody><tr><td><b>에이전트 라디우스</b></td><td>정수 integer</td><td>2</td><td>빈 공간이 통과 가능한 것으로 간주되기 위해 필요한 최소 수평 공간을 결정합니다.</td></tr><tr><td><b>에이전트 높이</b></td><td>정수 integer</td><td>5</td><td>빈 공간이 통과 가능한 것으로 간주되기 위해 필요한 최소 수직 공간을 결정합니다.</td></tr><tr><td><b>에이전트CanJump</b></td><td>부울</td><td>참</td><td>경로 찾기 중에 점프가 허용되는지 여부를 결정합니다.</td></tr><tr><td><b>에이전트CanClimb</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>비용</b></td><td>테이블</td><td>{}</td><td>재료 테이블 또는 정의된 <code>Class.PathfindingModifiedor|PathfindingModifiers</code>와 트래버스에 대한 "비용".에이전트가 다른 것보다 특정 재료/지역을 선호하도록 만드는 데 유용합니다.자세한 내용은 <a href="../../../characters/pathfinding.md#pathfinding-modifiers">여기</a>에서 확인하십시오.</td></tr></tbody>
키 |
---|
매개 변수
경로의 크기에 대한 미세 조정을 가능하게 하는 Luau 테이블(경로를 따라 이동하는 휴머노이드).유효한 키, 유형 및 설명은 위에서 참조하십시오.
반환
코드 샘플
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는 Enum.PathStatus.NoPath가 됩니다.
Path 개체의 경로점을 가져오려면 Path:GetWaypoints() 함수를 사용할 수 있습니다.