Quantcast
Channel: Yudiz Solutions Ltd.
Viewing all articles
Browse latest Browse all 595

Navigation System in Unity3D

$
0
0

Introduction

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:

  1. 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.
  2. 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.
  3. 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,
  4. NavMesh Obstacle NavMesh is an object that agent will avoid while navigating into the game World.

Building a NavMesh

The manner of creating a NavMesh from the extent is known as NavMesh Baking. All the objects that are static in the game world should be selected as Navigation Static. After check navigation, static click on bake button.

Step 1: All ground 3d Objects need to be selected as Static

Navigation System

Step 2: Go to Window > Navigation

Navigation System

Step 3: Select Object > All Check on Navigation Static And just hit Bake Button

Navigation System

After baking is done the blue surface area determines walkable surface in 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.

Navigation System

2. Set Transform Given below

Navigation System

3. Select Cylinder in hierarcy and Add Componet in inspector and then type nav mesh agent, it will add componet in cylinder.

Navigation System

4. Add Script to Cylinder AgentDirectionScript

Navigation System

5. Create empty game object, give name as destination and transform as shown below:

Navigation System

6. Add Code To the AgentDirectionScript

using UnityEngine;
using System.Collections;

public class AgentDirectionScript : MonoBehaviour
{
    //Reference of destination Transform
    public Transform destination;
   
    void Start()
    {
        //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

Navigation System

Now Hit play button, Nav Mesh Agent will automatically detect walkable area.

Milan Sadariya

Milan Sadariya | Jr. Game Developer

To create awesome experiences for serious gamers by leveraging my ability to work in a fast-paced environment with speed and accuracy, along with my course work and hands-on development experience.

Viewing all articles
Browse latest Browse all 595

Trending Articles