The Navigation System allows character which can navigate the game world. It gives your characters the capacity to remember that they want to take stairs to attain 2nd floor, or to jump to recover from a ditch. The Unity NavMesh include the following:
- NavMesh is a path finding mesh which allows you to determine walkable area in a game world. It is often used to find path from one walkable location to another in game world.
- NavMeshAgent part helps you to make characters which maintains a strategic distance from each other while moving towards their goal.the game global the use of the NavMesh and they know how to avoid each other.
- Off-Mesh It is a number which represents at what height character can jump. For example jumping over a ditch, or a door before walking through it,
- NavMesh Obstacle NavMesh is an object that agent will avoid while navigating into the game World.
Step 4: Now is the time to set our navMeshAgent that will walk on Blue Surface.
1. Create a cylinder: GameObject > 3D Object > Cylinder.
2. Set Transform Given below
3. Select Cylinder in hierarcy and Add Componet in inspector and then type nav mesh agent, it will add componet in cylinder.
4. Add Script to Cylinder AgentDirectionScript
5. Create empty game object, give name as destination and transform as shown below:
6. Add Code To the AgentDirectionScript
public class AgentDirectionScript : MonoBehaviour
//Reference of destination Transform
public Transform destination;
//GetComponent of navMeshAgent
NavMeshAgent agent = GetComponent<NavMeshAgent>();
//Set destination of navmeshAgent
agent.destination = destination.position;
7. Drag and Drop Destination Gameobject into AgentDirectionScript in destination
Now Hit play button, Nav Mesh Agent will automatically detect walkable area.