Question by
sctiendat · Mar 16, 2020 at 07:36 PM ·
navmeshnavigation
How to get a random point in the middle of nav mesh?
I have a problem asking for help.
I want to spawn random 1 item in the middle of 2 edges of the nav mesh. The code below describes how to get a random on my nav mesh now. However, I want to get the point in the middle of 2 nav mesh edges rather than any random point.
Who has any solution please tell me. Thanks!
Vector3 GetRandomLocation()
{
NavMeshTriangulation navMeshData = NavMesh.CalculateTriangulation();
int t = Random.Range(0, navMeshData.areas.Length);
// Select a random point on it
Vector3 point = Vector3.Lerp(navMeshData.vertices[navMeshData.indices[t*3]], navMeshData.vertices[navMeshData.indices[t*3 + 1]], 0.5f);
point = Vector3.Lerp(point, navMeshData.vertices[navMeshData.indices[t*3 + 2]], 0.5f);
return point;
}
screenshot-at-mar-16-20-01-06.png
(183.1 kB)
Comment
Your answer
Follow this Question
Related Questions
Off Mesh Link - Limiting access to certain agents 2 Answers
Best way of creating unity car ai that wonders around searching for player 1 Answer
Typical baking time for navigation on large terrains? 1 Answer
Instantiating a room onto a NavMesh during runtime - Walls are carving, but floors are not walkable. 0 Answers
How do I make sure my character is always perpendicular to the surface when using NavMesh? 0 Answers