반응형
- 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
반응형
'유니티' 카테고리의 다른 글
| unity navmesh random위치 구하기(sampleposition) (0) | 2025.08.26 |
|---|---|
| Random.insideUnitSphere (0) | 2025.08.26 |
| NavMesh.AllAreas/ NavMesh.GetAreaFromName (0) | 2025.08.26 |
| NavMesh.SamplePosition (NavMesh에 존재하는 가장 가까운 점찾기) (0) | 2025.08.26 |
| Unity Tmp 텍스트 부분 색 변경 (0) | 2025.08.25 |