UNITY AI SYSTEM
sources: https://docs.unity3d.com/Manual/nav-BuildingNavMesh.html
Last updated
sources: https://docs.unity3d.com/Manual/nav-BuildingNavMesh.html
Last updated
The Navigation System within Unity allows programs to create characters which can navigate the game world.
This gives characters the ability to understand that they need to... --> take the stairs to reach the second floor --> jump to get over the ditch
The Unity Navigation System consists of the following pieces:
NavMesh --> (short for Navigation Mesh) is a data structure which describes the walkable surfaces of the game world and allows characters to find paths from one walkable location to another in the game world --> Data structure is baked automatically from the level geometry
NavMesh Agent --> a component to help the program create characters which avoid each other while moving towards their goal --> Agents reason about the game world using the NavMesh and they know how to avoid each other as well as avoiding moving obstacles
OffMesh Link --> a component that allows you to incorporate navigation shortcuts which cannot be represented using a walkable surface --> Following examples can all be described as OffMesh Links ==> Jumping over a ditch or fence ==> opening a door before walking through it
NavMesh Obstacle --> a component that allows you to describe moving obstacles the agents should avoid while navigating the world --> Example of an obstacle would be a barrel/crate controlled by the physics system --> Agents will avoid moving obstacles while navigating the world --> Once obstacles become stationary it carves a hold in the mesh which forces agents to change their path to steer around it or to find a different route if it blocks their current path
The process of building a NavMesh from the level geometry is known as NavMesh Baking. The process collects the Render Meshes and Terrains of all Game Objects which are marked as Navigation Static then processes them to create a navigation mesh that approximates the walkable surfaces of the level.
Building a NavMesh can be done in 4 quick steps:
SELECTION --> Select geometry that should affect the navigation --> Walkable surfaces --> Obstacles
CHECK STATIC --> Check Navigation Static to include selected objects in the NavMesh baking process
ADJUSTMENTS --> Adjust the bake settings to match the programs AGENT size ==> AGENT RADIUS --> defines how close the agent center can get to a wall or a ledge ==> AGENT HEIGHT --> defines how low the spaces are that the agent can reach ==> MAX SLOPE --> defines how steep the ramps are that the agents can walk up ==> STEP HEIGHT --> defines how high obstructions are that the agent can step on
BAKE --> Click Bake to build the NavMesh
The NavMesh represents the are where the CENTER of the agent can move
NavMesh Agents are the AI characters within the program that need to navigate the scene
Creating a NavMesh Agent can be done in as few as 3 simple steps:
SELECTION --> Select the game object that should be an agent within the program [AGENT = AI CHARACTER]
ATTACHMENT --> Attach the NavMesh Agent Component to the selected game object --> Game Object is now a NavMesh Agent and is ready to receive commands from the program
SCRIPT --> Attach a script to the agent to control navigation. Navigation can be as simple as setting the desired destination point for the agent, the NavMesh Agent Component can handle everything from there --> In the script, the program will need... --> a reference to the NavMesh Agent Component --> Ability to assign a position to the NavMesh Agent Component's Destination Property
NavMesh Obstacle Components can be used to describe obstacles the agents should avoid while navigating
Creating a NavMesh Obstacle can be done in as few as 3 simple steps:
SELECTION --> Select the game object that should be an obstacle
ATTACHMENT --> Attach the NavMesh Obstacle Component and Rigidbody Component to the selected game object
ADJUSTMENT --> Turn on the CARVE setting from the NavMesh Obstacle Component --> Communicates to the agent to find a path around the obstacle
OffMesh Link Components are used to create paths crossing outside the walkable navigation mesh
OffMesh Links are represented by 2 game objects within the scene, whether they be hidden from the player or displayed in the scene.
Creating a NavMesh Link can be done in as few as
SELECTION --> Select the game object that will be the START of the shortcut path --> If there is a NavMesh Link to allow the AI character to jump from the balcony down to the floor, the STARTING game object would be one on the top of the balcony
ATTACHMENT --> Attach the OffMesh Link Component to the selected game object
ASSOCIATION --> Associate the starting game object to the START property and the end game object to the END property within the OffMesh Link Component