PathfindingService

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません
サービス
複製されていません

パス探索サービス は、2つのポイント間の論理的なパスを見つけるために使用され、文字が壁や他の障害物にぶつかることなくポイント間を移動できるようにします。デフォルトでは、最短のパスが計算されますが、定義された領域、または障害物を通じてより賢明なパスを計算するためのパス探索修正子を実装できます。

使用詳細は、キャラクターパスファインド を参照してください。

プロパティ

方法

CreatePath

複数のエージェントパラメータに基づいて Path オブジェクトを作成します。agentParameters テーブルの有効なキーと値は以下のとおりです:


<th>種類</th>
<th>デフォルト</th>
<th>説明</th>
</tr>
</thead>
<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>エージェント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>
キー

パラメータ

agentParameters: Dictionary

ルアウテーブルで、エージェントのサイズ (通路を移動するヒューマノイド) のパスを微調整できます。有効なキー、タイプ、および説明は、上記を参照してください。

既定値: "nil"

戻り値

A Path オブジェクト。

コードサンプル

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.

Creating a Path with Pathfinding Service

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

イールド

この機能は、2つの提供されたポイント間の Path を見つけるために使用されます。このパスは、PathfindingService によって作成されたナビゲーショングリッドを使用し、通常サイズの Roblox キャラクターでパスを追うことができるようにします。

この機能は、パスの座標を含む Path オブジェクトを返します。両点間にパスが見つからない場合、この関数は引き続き Path オブジェクトを返しますが、そのオブジェクトの Path.StatusEnum.PathStatus.NoPath になります。

Path オブジェクトのウェイポイントを取得するには、Path:GetWaypoints() 関数を使用できます。

パラメータ

start: Vector3

パス開始座標。

既定値: ""
finish: Vector3

パス終了座標。

既定値: ""

戻り値

A Path オブジェクト。

イベント