sourcePosition | レイの始点 |
targetPosition | レイの終点 |
hit | レイを飛ばしてヒットしたオブジェクトのプロパティー情報 |
areaMask | レイを飛ばす時、特定のマスクをかけるためにナビメッシュレイヤーを渡すことができる |
bool ターゲット位置に辿りつく前に終点となる場合は true、そうでない場合は false
ナビメッシュ上の二点間でレイを飛ばします
レイが始点から目標に向かってトレースされるとき、Source と Destination の点が NavMesh に最初にマップされます。レイが NavMesh 境界に当たった場合、関数は True を返し、ヒットデータが満たされます。 Source から目標へさえぎるものがない場合、関数は False を返します。
If the raycast terminates on an outer edge, hit.mask
is 0; otherwise it contains the area mask of the blocking polygon.
NavMesh で 2 点の間をエージェントが障害なく歩くことができる場合、確認として使用できます。たとえば、キャラクターがスペースが必要で回避しなければならない場合、キャラクターの場所から複数の方向にキャラクタが回避できる場所を見つけるためにレイを放つことができます。
NavMesh.Raycast は Physics Raycast とは異なります。これはNavMesh 上で "2.5 次元" で機能するものだからです。 Physics Raycast との違いは NavMesh 版は地面の穴などのようなナビゲーションの障害物のすべての種類を検出できます。エリアをナビゲートできるなら斜面を登るようなこともできます。
// TargetReachable using UnityEngine; using UnityEngine.AI;
public class TargetReachable : MonoBehaviour { public Transform target; private NavMeshHit hit; private bool blocked = false;
void Update() { blocked = NavMesh.Raycast(transform.position, target.position, out hit, NavMesh.AllAreas); Debug.DrawLine(transform.position, target.position, blocked ? Color.red : Color.green);
if (blocked) Debug.DrawRay(hit.position, Vector3.up, Color.red); } }
NavMesh で最も近い点を見つけるために探している場合、ワールドで点を見つけるために Physics Raycast を使用する必要があります。 Move to Click Point の例を参照してください。
sourcePosition | レイの始点 |
targetPosition | レイの終点 |
hit | レイを飛ばしてヒットしたオブジェクトのプロパティー情報 |
filter | A filter specifying which NavMesh areas can be passed when tracing the ray. |
bool ターゲット位置に辿りつく前に終点となる場合は true、そうでない場合は false
Traces a line between two positions on the NavMesh, subject to the constraints defined by the filter argument.
The line is terminated on outer edges or a non-passable area.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.