Can you make one agent follow the same path as another?

One of the formations in my game is the file formation, one soldier directly behind the other. I have noticed that it is very hard to get two soldiers to take the exact same path. I passed the entire buffer from GetRemainingPath to the next soldier telling him to hit each point and he still took a different path. So I was wondering if it is possible to just send a whole path to another soldier?

IEnumerator MoveInFile(List buffer)
{
for (int i = 0; i < (buffer.Count - 1); i++)
{
teamMemberScripts[1].StartCoroutine(“MoveToRallyPoint”, buffer[i]);
while (teamMemberScripts[1].path.reachedEndOfPath == false)
{
yield return null;
}
}
if (buffer[buffer.Count - 1] != rallyPoint)
{
MovementDirector();
}
else
{
Vector3 offSet1 = OffSet1();
teamMemberScripts[1].StartCoroutine(“MoveToRallyPoint”, (rallyPoint + offSet1));
}
}

Hi

Which movement script are you using?

One alternative common approach for this is to continuously set the destination of each agent to the position where the agent it is following was a second or so ago.

FollowerEntity

I thought about doing that but could not figure out a way to set that up.

Seriously can you talk me through it. That sounds like a better way to do this than using the buffer.
I am thinking it would be an IEnumerator File(int i), that would save soldier[i - 1].transform.position, it would have a while loop, and a yield return new waitForSeconds(1f) that then tells soldier[i] where to move. I just can’t put it together into real code. Can you please help?

Never mind I got it:

IEnumerator FileMovement(int i)
{
teamMemberScripts[i].StartCoroutine(“MoveToRallyPoint”, teamMembers[i - 1].transform.position);
while (Vector3.Distance(teamMembers[i].transform.position, rallyPoint) > (3f * i) && teamMemberScripts[0].path.reachedEndOfPath == false)
{
Vector3 target = teamMembers[i - 1].transform.position;
yield return new WaitForSeconds(.25f);
teamMemberScripts[i].StartCoroutine(“MoveToRallyPoint”, target);
}
teamMemberScripts[i].stopAction = true;
}

1 Like