본문 바로가기
유니티

NavMeshHit hit

by 유니티세상 2025. 8. 26.
반응형

 

 

  • SamplePosition, Raycast 등의 결과가 담기는 구조체.
  • 대표 필드:
    • position: 맞은 지점의 월드 좌표
    • normal: 표면 노멀
    • distance: 원본 좌표와의 거리(또는 레이 원점과의 거리)
    • mask: 해당 폴리곤의 Area 마스크
  • 디버깅 시 hit.position만 써도 충분하지만, 경사(경사 제한)나 Area 구분이 필요하면 normal, mask도 활용합니다.

  private bool RandomPoint(Vector3 center, float range, out Vector3 result)
  {
      for (int i = 0; i < 30; i++)
      {
          Vector3 randomPoint = center + Random.insideUnitSphere * range;
          NavMeshHit hit;

          if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas))
          {
              result = hit.position;
              return true;
          }
      }
      result = Vector3.zero;
      return false;
  }

 

 

https://ansohxxn.github.io/unitydocs/navmeshhit/

 

Unity C# > UnityEngine : NavMeshHit

공부하면서 알게된 것만 정리합니다.😀

ansohxxn.github.io

 

반응형