Unity3D: Smart AI with the Nav Mesh System
Let’s make our AI smarter when navigating around objects!
Objective
As a follow-up to my last article, I will show you how to have your player or AI move around objects on the nav mesh system.
Unintelligent Agent
If we were to move in its current state, the agent passes through objects. We don’t want that! It’s not logical for what we want. Here’s an example of our unintelligent agent.
In the scene view, the blue represents the area where the agent can translate to. We can also see that the agent passes through obstacles.
We need to fix this matter so that we can have our agent go around the obstacles instead.
Obstacles to Static
We need to select all of our obstacles, and on the top right of the inspector, we need to check the static box.
A pop-up box appears. Select “Yes, Change Children.” We want to ensure all the children under the “Obstacles” game object are static as well.
Baking
We now need to recalculate the nav mesh! We need to go to our Navigation window. Under the Bake tab, we hit the Bake button at the bottom right.
It will recalculate the nav mesh by adding a rim around the obstacles!
Conclusion
With the nav mesh system taking information where the obstacles are in place, we now have an intelligent agent! It will only translate to the blue areas on the ground. The static obstacles, with a re-bake to the nav mesh ground, made it possible!
That is all for today. Thank you for your time!
Gabriel