Version: 2023.2
言語: 日本語
public static bool CalculatePath (Vector3 sourcePosition, Vector3 targetPosition, int areaMask, AI.NavMeshPath path);

パラメーター

sourcePosition リクエストした初期位置
targetPosition リクエストした目的地
areaMask パスの計算時に特定のマスクをかけるためにナビメッシュレイヤーを渡すことができる
path 計算結果のパス

戻り値

bool True if either a complete or partial path is found. False otherwise.

説明

2 点間の位置を計算して、ナビメッシュオブジェクト上で移動できる範囲のパスを作成します

Use this function to avoid gameplay delays by planning a path before it is needed. You can also use this function to check if a target position is reachable before moving the agent.

This function is synchronous. It performs path finding immediately which can adversely affect the frame rate when processing very long paths. It is recommended to only perform a few path finds per frame when, for example, evaluating distances to cover points.

Use the returned path to set the path for an agent with NavMeshAgent.SetPath. For SetPath to work, the agent must be close to the starting point.

// ShowGoldenPath
using UnityEngine;
using UnityEngine.AI;

public class ShowGoldenPath : MonoBehaviour { public Transform target; private NavMeshPath path; private float elapsed = 0.0f; void Start() { path = new NavMeshPath(); elapsed = 0.0f; }

void Update() { // Update the way to the goal every second. elapsed += Time.deltaTime; if (elapsed > 1.0f) { elapsed -= 1.0f; NavMesh.CalculatePath(transform.position, target.position, NavMesh.AllAreas, path); } for (int i = 0; i < path.corners.Length - 1; i++) Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.red); } }

public static bool CalculatePath (Vector3 sourcePosition, Vector3 targetPosition, AI.NavMeshQueryFilter filter, AI.NavMeshPath path);

パラメーター

sourcePosition リクエストした初期位置
targetPosition リクエストした目的地
filter A filter specifying the cost of NavMesh areas that can be passed when calculating a path.
path 計算結果のパス

戻り値

bool 完全な、あるいは部分的にパスが見つかった場合、True 。それ以外の場合は False 。

説明

Calculates a path between two positions mapped to the NavMesh, subject to the constraints and costs defined by the filter argument.