- Home /
How to stop NPCs from walking in a line?
This may be a dumb question, or one already answered, but how can I make my NPCs walk offset from each other? My enemies are walking into each other or in a straight line to get to their common destination. I want them to act more like a squad, being more spread out to get to their point. Is there like a spread variable for the navmesh?
I am using the nav mesh agent to control where the NPCs are head towards, this is my script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI;
public class TargetFlag : MonoBehaviour {
public GameObject player;
NavMeshAgent agent;
// Use this for initialization
void Start ()
{
player = GameObject.Find ("Flag");
agent = gameObject.GetComponent<NavMeshAgent> ();
}
// Update is called once per frame
void Update ()
{
agent.SetDestination (player.transform.position);
}
}
Please tell me if there is more information I need to provide, thx :)
If this question has been answered, would you mind sharing the link?
You could deter$$anonymous$$e the closest actor to the target position, and make everyone one choose target points relative to their current position to the "leader".
Have you found a solution to this problem? I am facing the same problem and can't find a way to solve it
Answer by metalted · Jul 09, 2019 at 05:09 AM
You could make use of "Flocking", where objects look at their closest neighbors to determine there own position. The direction they are going is based on the global direction of the group. There are a lot of videos and tutorials on this subject.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
NavAgent messing up rotation after using NavLink 0 Answers
Distribute terrain in zones 3 Answers
How can I get a character to patrol and follow terrain? 1 Answer
Health not being subtracked. 1 Answer