NNInfo
GetNearest
(
Vector3 | position | The point to find nodes close to |
NNConstraint | constraint | The constraint which determines which graphs and nodes are acceptable to search on. May be null, in which case all nodes will be considered acceptable. |
)
Returns the nearest node to a point using the specified NNConstraint.
Searches through all graphs for their nearest nodes to the specified position and picks the closest one. The NNConstraint can be used to specify constraints on which nodes can be chosen such as only picking walkable nodes.
GraphNode node = AstarPath.active.GetNearest(transform.position, NearestNodeConstraint.Walkable).node;
var constraint = NearestNodeConstraint.None;
// Constrain the search to walkable nodes only
constraint.walkable = NearestNodeConstraint.WalkabilityConstraint.Walkable;
// Constrain the search to only nodes with tag 3 or tag 5
// The 'tags' field is a bitmask
constraint.tags = (1 << 3) | (1 << 5);
var info = AstarPath.active.GetNearest(transform.position, constraint);
var node = info.node;
var closestPoint = info.position;
DeprecatedThis method is obsolete. Use the overload that takes a NearestNodeConstraint instead.