Is it possible to do a raycast against the navmesh? The use-case is randomly spawning characters in a region, and I need to raycast against the navmesh to ensure I’m placing the character at a walkable location.
I suspect raycasting against navemesh to get a collision point is a common thing, but I’ve been unable to find an example.
Navmesh you must to drag manually your mesh into the Pathfinding. I simple create a other GameObject with a mesh collider and drag the same mesh to it.
Could be a misunderstood? I am not talking about RecastGraph.
Or maybe not. This is unity3d, nothing could be difficult
Try to dig into the code, the beautiful of source access. 10 seconds look into Pathfinding.RecastGraph class I found the method GetSceneMeshes. Could not be it, but I found some references to Mesh, and this, is what are you looking for.
The easiest method is to simply get the closest valid point.
`
// using Pathfinding; // At top of script
Vector3 p = Random.insideUnitSphere * 100;
NNInfo info = AstarPath.active.GetNearest ( p, NNConstraint.Default );
if ( info.node == null ) Debug.LogError (“Could not find any nodes, try increasing A* Inspector -> Settings -> Max Nearest Node Distance”);
p = info.clampedPosition;
`
You can also get the actual mesh using
`
RecastGraph graph = AstarPath.active.astarData.recastGraph;
graph.GetNodes ( delegate ( GraphNode node ) {
TriangleMeshNode tnode = node as TriangleMeshNode;
// The tnode variable contains everything you would want to know about a single triangle/node in the mesh
return true;
}`
The actual nodes are stored in the recast graph inside a number of tiles.