Question by
Molmez · Apr 15, 2017 at 12:18 AM ·
navmeshagentnavigationnavagentnav
How to assure Navagents maintain a certain distance from one another while following same path?
Heya,
I am creating a waypoint system for navagents to follow. It works well however say I have 4 agents following the same path. I do not want them to catch up with each other and be walking in a group along the path!
How do I force each agent to keep a certain distance from one another so they stay in formation?
Thank you.
Current agent movement code:
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine.AI;
public class AIBase : MonoBehaviour
{
private Transform player;
private NavMeshAgent nav;
public Transform[] Movepoints;
private Transform currentPos;
private int _movePointIndex = 0;
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
nav = GetComponent <NavMeshAgent> ();
nav.SetDestination(Movepoints[_movePointIndex].transform.position);
}
void Update ()
{
if (nav.remainingDistance < 1)
{
_movePointIndex += 1;
if(_movePointIndex >= Movepoints.Length)
{
_movePointIndex = 0;
}
nav.SetDestination (Movepoints [_movePointIndex].transform.position);
nav.updateRotation = false;
}
}
}
Comment