get random point on navmesh code example

Example 1: get random point on navmesh

Vector3 randomDirection = Random.insideUnitSphere * walkRadius;
 randomDirection += transform.position;
 NavMeshHit hit;
 NavMesh.SamplePosition(randomDirection, out hit, walkRadius, 1);
 Vector3 finalPosition = hit.position;

Example 2: get random point on navmesh

randomDirection += transform.position; NavMeshHit hit; NavMesh.SamplePosition(randomDirection, out hit, walkRadius, 1); Vector3 finalPosition = hit.position;

Example 3: get random point on navmesh

Vector3 randomDirection = Random.insideUnitSphere * walkRadius;