Uhhh…I think I’ll let the pictures explain here. Head hurt…
It seems to be possible to only calculate the route once at the start of the route and again when somethings unexpected happen (i.e. the unit run into an obstacle, or get pushed away because of the cell is overcrowd), rather than have it recalculated every cell as it is now. Although all route data are current cached for half a second on all cells, so I am not sure of how much more effective that would be.
If this is implemented with Follow the Leader algorithm, it might be possible to only require pathfinding for the first unit of a flock. This unit might be possible to be identified when either;
- It can detect no neighboring unit in front of it or
- The cell in front of it is empty
All direction calculation should be added to the direction vector, then recalculate a unit-vector before applying the speed. Making sure that the forward-speed reduce when they steer to the side, possibly causing more dynamic in the group.