Mike H
Mike H

Reputation: 407

Unity limit physics walkable area to navmesh mesh

I'm using physics to control my players and navmesh/agent for AI NPCs and occasional player movement. I'm wondering if there is a way to limit my walkable area for the player, when using physics to move, to the exact baked mesh from the navmesh so that the coverable ground is constant between the two.

Thanks in advance

Upvotes: 2

Views: 905

Answers (1)

Mockarutan
Mockarutan

Reputation: 442

One way could be to get the actually mesh in the navmesh and construct some sort of collision from it. You can get the actual mesh like this:

UnityEngine.AI.NavMeshTriangulation triangulatedNavMesh = UnityEngine.AI.NavMesh.CalculateTriangulation();

Mesh mesh = new Mesh();
mesh.name = "ExportedNavMesh";
mesh.vertices = triangulatedNavMesh.vertices;
mesh.triangles = triangulatedNavMesh.indices;

Then a recommendation for C# trigonometry calculations (like finding the convex hull and such) is NetTopologySuite

Upvotes: 1

Related Questions