Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

how can i get y (hight) of Navmesh

Discussion in 'Navigation' started by naorgueva, Oct 16, 2019.

  1. naorgueva


    Apr 11, 2019
    i want a frog to move randomly on the Navmesh.
    so i have a random Vector3 in a Sphare radius (around the frog)
    i take the Vector3.Y and i move it up 800f (to make sure that its not under ground)
    then i shoot a ray down 1,000f in length.(to make sure im passing the ground)
    now if im hitting the ground im setting the NavMeshAgent to hit.point

    im trading to make a game without physics so i cant use Raycast.
    correctly im casting a ray to determine the y of the floor.

    i have Z and X axis.
    can i find the y in a different way? (without physics )
    can i get the correct Y on the navmesh surface?

    Code (CSharp):
    1.     private void JumpAround()
    2.     {
    4.         Vector3 pointInSphare = Random.insideUnitSphere * _sphareRad;
    5.         pointInSphare.y = 800;
    8.         Ray ray = new Ray(pointInSphare, Vector3.down);
    9.         RaycastHit hit;
    11.         if(Physics.Raycast(ray ,out hit, 1000.0f,  Layer))
    12.         {
    13.             pointInSphare = hit.point;
    14.             _thisNavMeshAgent.SetDestination(pointInSphare);
    15.         }
    16.     }