Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NavMesh.FindClosestEdge

static function FindClosestEdge(sourcePosition: Vector3, hit: NavMeshHit, passableMask: int): bool;
static bool FindClosestEdge(Vector3 sourcePosition, NavMeshHit hit, int passableMask);
static def FindClosestEdge(sourcePosition as Vector3, hit as NavMeshHit, passableMask as int) as bool

Parameters

sourcePositionThe origin of the distance query.
hitHolds the properties of the resulting location.
passableMaskA mask specifying which NavMesh layers can be passed when finding the nearest edge.

Returns

bool True if a nearest edge is found.

Description

Locate the closest NavMesh edge from a point on the NavMesh.

The returned NavMeshHit object contains the position and details of the nearest point on the nearest edge of the navmesh. Since an edge typically corresponds to a wall or other large object, this could be used to make a character take cover as close to the wall as possible.

	var mesh: NavMesh;
	var player: Transform;

// Move a marker object to show a position of cover // that the player should head for. function IndicateCoverPosition() { var hit: NavMeshHit; if (mesh.FindClosestEdge(player.position, hit, -1)) { transform.position = hit.position; } }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public NavMesh mesh;
    public Transform player;
    void IndicateCoverPosition() {
        NavMeshHit hit;
        if (mesh.FindClosestEdge(player.position, out hit, -1))
            transform.position = hit.position;
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public mesh as NavMesh

	public player as Transform

	def IndicateCoverPosition() as void:
		hit as NavMeshHit
		if mesh.FindClosestEdge(player.position, , -1):
			transform.position = hit.position