Version: 2020.2
言語: 日本語
public static bool FindClosestEdge (Vector3 sourcePosition, out AI.NavMeshHit hit, int areaMask);

パラメーター

sourcePosition クエリとなる距離の原点
hit 一番近い辺のヒット情報
areaMask もっとも近い辺を求めるときに特定のマスクをかけるためにナビメッシュレイヤーを渡すことができる

戻り値

bool True if the nearest edge is found.

説明

特定の位置からもっとも近いナビメッシュオブジェクトの辺の情報を取得します

返される NavMeshHit オブジェクトは NavMesh の最寄りの端に最も近いポイントの位置と詳細が含まれています。 これを使用してエージェントの周りにどのくらいの余分なスペースがあるか参照するために使用できます。

// MeasureSpace
using UnityEngine;
using UnityEngine.AI;

public class MeasureSpace : MonoBehaviour { void DrawCircle(Vector3 center, float radius, Color color) { Vector3 prevPos = center + new Vector3(radius, 0, 0); for (int i = 0; i < 30; i++) { float angle = (float)(i + 1) / 30.0f * Mathf.PI * 2.0f; Vector3 newPos = center + new Vector3(Mathf.Cos(angle) * radius, 0, Mathf.Sin(angle) * radius); Debug.DrawLine(prevPos, newPos, color); prevPos = newPos; } }

void Update() { NavMeshHit hit; if (NavMesh.FindClosestEdge(transform.position, out hit, NavMesh.AllAreas)) { DrawCircle(transform.position, hit.distance, Color.red); Debug.DrawRay(hit.position, Vector3.up, Color.red); } } }

public static bool FindClosestEdge (Vector3 sourcePosition, out AI.NavMeshHit hit, AI.NavMeshQueryFilter filter);

パラメーター

sourcePosition クエリとなる距離の原点
hit 一番近い辺のヒット情報
filter A filter specifying which NavMesh areas can be passed when finding the nearest edge.

戻り値

bool True if the nearest edge is found.

説明

Locate the closest NavMesh edge from a point on the NavMesh, subject to the constraints of the filter argument.

The returned NavMeshHit object contains the position and details of the nearest point on the nearest edge of the NavMesh. This can be used to query how much extra space there is around the agent.