Playing around with NavMeshAgent to create some pedestrians in my town.
here's a Quick Setup Steps: 1. Mark everything with a collider that doesn't move as "static"
![](https://static.wixstatic.com/media/a27d24_a9d8ee15c3dd47138d6787e3f3577230~mv2.png/v1/fill/w_980,h_292,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_a9d8ee15c3dd47138d6787e3f3577230~mv2.png)
2. Create a NavMesh Baked Area for those "static" object - Windows > AI > Navigation - Bake menu > click "Bake" this will create a walkable area for our NavMeshAgent
![](https://static.wixstatic.com/media/a27d24_dc9fc4ab28164c61a675b61cb2b9f763~mv2.png/v1/fill/w_569,h_110,al_c,q_85,enc_auto/a27d24_dc9fc4ab28164c61a675b61cb2b9f763~mv2.png)
3. For everything else that moves (and does not contain a NavMeshAgent ), add the "Nav Mesh Obstacle" component to it.
![](https://static.wixstatic.com/media/a27d24_33d8e24b39ec4e3286d021f6866e7f7f~mv2.png/v1/fill/w_566,h_354,al_c,q_85,enc_auto/a27d24_33d8e24b39ec4e3286d021f6866e7f7f~mv2.png)
4. Create NavMeshAgent component on our moving NPC
Note: NavMeshAgent also works as NavMesh Obstacle, therefore, no need to add NMO to the object with NavMeshAgent .
![](https://static.wixstatic.com/media/a27d24_1dcac709fb9c439d90f1188d78506f65~mv2.png/v1/fill/w_541,h_329,al_c,q_85,enc_auto/a27d24_1dcac709fb9c439d90f1188d78506f65~mv2.png)
5. Add Script component and call for navMeshAgent.SetDestination(V3 position) 6. DONE!! NavMeshAgent can now move around the scene.
Tips : 1. Set NPC's Rigidboy to Kinemetic will save you from headaches. 2. You can put SetDestination(V3) in Update() loop if your destination is moving. Just note that it's not effective to put a pathfinding function in frameloop(especially for mobile). #Unity #NavMeshAgent
Comments