How to redo NavMeshHit position if out of range of X and Z of Navmesh?
How would I set NavMeshHit only on the Y axis and otherwise redo the setting of randDirection. I want the NavMeshAgents to avoid hanging around the edges in a small space.
public static Vector3 RandomNavSphere(Vector3 origin, float dist, int layermask)
{
Vector3 randDirection = Random.insideUnitSphere * dist;
randDirection += origin;
NavMeshHit navHit;
NavMesh.SamplePosition(randDirection, out navHit, dist, layermask);
return randDirection;
}
Comment