top of page
Writer's pictureCallum Pearce

Unit Formations


In one of my previous blog posts I considered putting some thought into the combat system. As I did, I realised it isn't all that complicated. So while I still had some extra time without any other projects on I decided to look at a slightly more challenging subject of unit formations.

Unit formations occur in RTS games when multiple units are selected and sent to one point. Without this, all units will travel to that exact point, and either all stack up on top of each other if they have no collision detection (my case) or if they do they will all be fighting for that one point. To solve this issue I have researched a few different ways that this can be done. The first method was fairly simple and in my eyes isn't as much a formation, and more just a way to sort units at the end of their path. This is to have each unit use the pathfinding to create a path from it's position to a set target position depending on the formation defined. This works but has a couple problems. First of all it breaks the illusion of the formation, as they each are travelling their own path. Sometimes it can look correct, but that would just be due to coincidence as they moved together. But if the pathfinding takes them around an object, the sort of formation created breaks. A secondary problem is the performance this takes up when the amount of units are scaled. This will require further pathfinding searches to be made which as unit sizes get bigger it can slow down the game.

An alternative method of formations is a little bit more complicated but solves these two problems. This method involves taking the average position of all the selected units and creating a formation object at that position. Then this object will make a pathfinding search towards the target location. Then each unit within that formation, is assigned to a certain position in a given formation. This position contains a Vector3 and the unit associated with it. The Vector3 stores the offset from the centre of the formation that corresponds to the matching world position. The unit then moves to this position every frame until the formation object has stopped. This fixes the problem regarding the formation illusion and the amount of pathfinding searches made. But also introduces a new problem that didn't occur with the simpler version before.

This problem is collision avoidance. (Now currently I have implemented a formation, and have the offsets defined to move the units to the correct places. I have not yet implemented collision avoidance, and the following is how I believe it should be done.) As the units are moving to an offset from the centre, if the centre is next to an unwalkable area, there is a high chance some of the formation positions are in that unwalkable area, so each unit needs to have a steering behaviour to alter it's direction and velocity to move around the unwalkable area. Then once past the it, they will move back to the correct position.

Below are examples of my formation with unit sizes 4, 6, 8, 11 and 25.

4 Unit Formation
6 Unit Formation
8 Unit Formation
11 Unit Formation
25 Unit Formation

26 views0 comments

Recent Posts

See All
bottom of page