Hey guys,
I'm working on a game where you can control regiments consisting of several units similar to the Total War series. My problem is that I'm not satisfied with how these regiments reform when giving an order that requires rotation of the current formation. The way it is now is not game breaking but really not optimal. What I basically do is allow the unit that is furthest from the destination to pick its preferred spot. That would result in low cost solutions if it weren't for collision. It also just doesn't look right. Here is an image to illustrate an instance that I feel needs improvement.
As you see the unit in the front crosses the path of nearby units which causes collisions and delays. What I need is for units to not cross other's paths if it would cause complications. The problem is that similiar constellation need different solutions depending on unit positions. In this image we have two similiar constellations that need different solutions because otherwise there would be collisions.
In the first case you wouldn't want them to cross their paths because you might risk collision although that means a longer distance for the unit that is already behind. In the second case however you would want them cross their paths. There is no risk of collision as they are too far apart and you shorten the distance for the unit that is behind. They even have to cross paths because otherwise the unit that is behind would collide with the one in the front when trying to move past it on its way to its destination.
So what is the best way to guarantee a smooth flow of units without unnecessary path crossings? It works perfectly in the Total War games. I'd really like to know how to do it.
I'm pretty sure there are established solutions to this in the industry. I'm just too uneducated in programming to know them.