- Home /
Random Position on Nav Mesh
I would like to move my game character, which is a navmesh agent to a random position on a Nav Mesh. I have the character moving, i just need to choose a random walkable position.
I am using this line to move to a specific object:
GetComponent<NavMeshAgent>().destination = theObject.position;
Thanks
Answer by Branx · Jun 11, 2012 at 03:07 PM
You could write a Script which takes random values for X and Z.
transform.position = Vector3(Random.value 100, yourNavMeshHeight , Random.value 100, );
But i guess in any game you're better off placing your SpawnLocators manually.
Thanks, but the problem with this is the mesh agent might be sent off to a position it cant reach, a non walkable area. The agent would just get stuck trying to reach the new position.
Your answer
Follow this Question
Related Questions
Can you use NavMesh agents to vary driving/handling model? 0 Answers
Moving rigidbodies at random 1 Answer
How to make AI "roam around" convincingly on a navmesh? 2 Answers
Navmesh one way gate 0 Answers
Agents taking wrong path 0 Answers