Function PointGraph.RandomPointOnSurface
A random point on the graph.
NNInfo RandomPointOnSurface (
nnConstraint=null | Optionally set to constrain which nodes are allowed to be returned. If null, all nodes are allowed, including unwalkable ones. |
|
bool | highQuality=true | If true, this method is allowed to be more computationally heavy, in order to pick a random point more uniformly (based on the nodes' surface area). If false, this method should be fast as possible, but the distribution of sampled points may be a bit skewed. This setting only affects recast and navmesh graphs. |
A random point on the graph.
If there are no suitable nodes in the graph, NNInfo.Empty will be returned.
// Pick a random walkable point on the graph, sampled uniformly over the graph's surface
var sample = AstarPath.active.graphs[0].RandomPointOnSurface(NNConstraint.Walkable);
// Use a random point on the surface of the node as the destination.
var destination1 = sample.position;
// Or use the center of the node as the destination
var destination2 = (Vector3)sample.node.position;