SamplePathPosition(int, float, out NavMeshHit)
Sample a position along the current path.
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Method
- Namespace: UnityEngine.AI
- Assembly: UnityEngine.AIModule
SamplePathPosition(int, float, NavMeshHit)
public bool SamplePathPosition(int areaMask, float maxDistance, out NavMeshHit hit)
Parameters
A bitfield mask specifying which NavMesh areas can be passed when tracing the path.
Terminate scanning the path at this distance.
Holds the properties of the resulting location.
Returns
Type | Description |
|---|---|
| bool | True if terminated before reaching the position at |
Remarks
This function looks ahead the specified along the current path, up to the third corner. It returns details of the mesh at that position in a NavMeshHit object. You can use this to check the type of surface that lies ahead before the character gets there. For example, characters could raise their guns above their heads if they are about to wade through water.
maxDistanceIf the path sampling terminates on an outer edge, is 0. If the path sampling terminates at an area not specified by , contains the area mask of the blocking polygon. If the sampling reaches the end of the path, or the limit at the path's third corner, contains the area mask at that position on the NavMesh.
hit.maskareaMaskhit.maskhit.maskExamples
using UnityEngine;using UnityEngine.AI;using System.Collections;public class ExampleClass : MonoBehaviour{ public Transform target; private NavMeshAgent agent; private int waterMask; void Start() { agent = GetComponent<NavMeshAgent>(); waterMask = 1 << NavMesh.GetAreaFromName("Water"); agent.SetDestination(target.position); } void Update() { NavMeshHit hit; // Check all areas one length unit ahead. if (!agent.SamplePathPosition(NavMesh.AllAreas, 1.0F, out hit)) if ((hit.mask & waterMask) != 0) { // Water detected along the path... } }}