(Created page with "The NavMesh function in Unity can help you define your region where is walkable and where is not, so if you have an auto-walk function for player or NPC, it can automatically...") |
|||
Line 1: | Line 1: | ||
The NavMesh function in Unity can help you define your region where is walkable and where is not, so if you have an auto-walk function for player or NPC, it can automatically calculate the routes. | The NavMesh function in Unity can help you define your region where is walkable and where is not, so if you have an auto-walk function for player or NPC, it can automatically calculate the routes. | ||
− | If you are interested in how to fully use the NavMesh function, please check | + | If you are interested in how to fully use the NavMesh function, please check [https://unity3d.com/cn/learn/tutorials/topics/navigation/navigation-overview?playlist=17105|the official tutorial of Unity]. |
Here, we will only introduce some basic method. | Here, we will only introduce some basic method. |
The NavMesh function in Unity can help you define your region where is walkable and where is not, so if you have an auto-walk function for player or NPC, it can automatically calculate the routes.
If you are interested in how to fully use the NavMesh function, please check official tutorial of Unity.
Here, we will only introduce some basic method.
As an example, I created a region with some simple objects as obstacles.
First, Click the menu Window -> Navigation to call out the Navigation window(In Unity 2018, it's in Window -> AI -> Navigation). There are four tabs in Navigation Window: Agents, Areas, Bake and Objects.
The Agents tab is a place to record profiles for different parameters, when you attach Nav Mesh Agent component to a character, you can choose the agent profile you set in the agents tab.
The Areas tab is for define the layers of navigation. There is already 3 built-in layer: Walkable, Not Walkable and Jump. You can always add new layer if you need. The Cost defines whether the layer is hard to walk or not -- more cost, much harder. Normally, the Auto-walk will always choose a path with lower cost.
The Object tab is to set the navigation parameter for the objects in the scene. The 3 filters, All, Mesh Renderers, Terrains can help you to find the objects, and if we need to set an object walkable or not, pick the checkbox Navigation Static, then choose its layer. If you want set it jumpable, for example: jump across a gap between two platform, of jump down from somewhere high, you should also pick the Generate OffMeshLinks checkbox then choose the Jump layer for Navigation Area.
The Bake tab includes all detail settings here. The Agent Radius defines the width of character and how narrow the path it could pass. Agent Height stands for the height of character, so if there is a height limitation area, the character shall not pass. Max Slope defines the maximum angle the character can move on, and objects lower than the step height will not be considered as an obstacle. Drop Height is the maximum height which the character can jump off, and jump distance is a horizontal distance which the character can jump across.
When all the settings are done, you can click the Bake button to generate the NavMesh Map. When it's complete, the Scene window will display the Navmesh map.
The NavMesh jumpable with off-Mesh links will have an arrow and circle like this: