# Getting a group of units to follow a predetermined patrol path

I want to have a group of units follow a predetermined path, and want to know the best way to do this. I have a way of doing this now, but it’s causing me a lot of problems, and am wondering if there is a better solution to the problem.

Basically:

`waypointIndex = 0 while (true) if hasReachedEndOfPath waypointIndex = waypointIndex+1 if waypointIndex >= number of waypoints waypointIndex = 0 calculate new path to waypoint follow path`
Don’t think there is a much better way.

PS: Sorry for taking a long time to answer.

That’s the gist of what I’m doing right now, but in practice it ends up getting more complicated. Since I’m moving a group of units, the waypoint check radius is a function of how many other units are nearby. I end up calling Physics.OverlapSphere around the waypoint, and adjust the waypoint check radius based on the density of units nearby.

Adjusting that density is somewhat tricky though. If it’s too small, the units move around too losely. If it’s too large, a unit will sometimes get pushed past the waypoint by other units, and will have to backtrack once it gets separated enough from the other units. This looks pretty funny.

So I posted just to see if there is a simpler way that I’m just overlooking.

For instance, in TD games, units can be made to “follow” a common path simply because they are all just heading to the same destination. I was wondering if there is some similar effect that can be achieved on an arbitrary patrol path. Perhaps not …

Well, I don’t think there is a much easier way of dynamically adjusting the waypoint check radius. TD games usually just force them to walk in a line with a constant waypoint check radius.
Sorry but I can’t think of one.

Yeah, looks like I’ll be sticking with my current method then.

Thanks for the input.