AI Navigation

From STEAMwiki
Jump to: navigation, search

NavMeshUnderstandingAreas.png

Navigation overview: https://docs.unity3d.com/Manual/nav-InnerWorkings.html

Adding navigation elements

https://docs.unity3d.com/Manual/nav-BuildingNavMesh.html

Open Navigation window. Select the objects that are a part of your navigation terrain and obstacles. Click on the "Navigation Static" checkbox for each.

Agent Components

Add the Nav Mesh Agent component to the agent you want to navigate with AI.

Add this script for it to seek out a goal:

// MoveTo.cs
using UnityEngine;
using System.Collections;

public class MoveTo : MonoBehaviour
{
    public Transform goal;
    UnityEngine.AI.NavMeshAgent agent;

    void Start()
    {
        agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
        agent.destination = goal.position;
    }

    private void Update()
    {
        agent.destination = goal.position;
    }
}