SamplePosition hit.normal returned 0,0,0 … “by design”.
So, to get an agent to hug the ground another method is necessary.
I’m currently shooting 5 raycasts down the ground at 30 degree angle from the vertical, then averaging them.
I was wondering if you all had a more performant approach…Apart from tearing unity navmesh and replacing it with AnyPath or A*
In the absence of any functionality to obtain the normal from NavMesh polygons two ways to do it would be:
- Get all triangles with NavMesh.CalculateTriangulation(), then find the triangle at that position and deduce the normal.
- Use NavMeshQuery.MapLocation() to get the polygon ID, then NavMeshQuery. GetEdgesAndNeighbors() to get the polygon vertices, then compute the normal. Disclaimer: NavMeshQuery is deprecated and unsupported. It’s not recommended to use it in production. It could work fine for this specific case but evaluate it thoroughly.
These two provide data about the main NavMesh polygons and not about the detail triangles of the NavMesh, which are used to represent the elevation more precisely when the agent moves.
This one looks promising. When you say deprecated, when was it nuked? I don’t see such tag in 2020.3
And what replaced it in new versions of Unity?
NavMeshQuery is deprecate as of Unity 6 (more precisely 2023.2). Nothing replaces it. It was/is an experimental API.
Something should replace it, spatial queries in AI is a big deal.
