Coordinated Unit Movement

After over a year, time for my second post ever about making games!

This time I’ll go over a handy technique used in making AI for games called Coordinated Unit Movement.

Coordinated Movement: What Is It?

So when I say coordinated movement, what I’m talking about is having a group of units (could be anything based on the type of game) and making them position themselves or move in an organized fashion. For example:

aiex

From Ian Millington’s Aritficial Intelligence for Games, we have this image of some basic static formations. As you can see, for each formation we’ve got four units that are positioned in a planned way. The idea with coordinated movement is to have the units move towards a goal while maintaining these formations if possible. So the group in the top-right would try to move to their goal while staying in a line shape. Pretty simple right? However the work involved to make units move like this is a bit more than just placing them like this and giving them the same goal.

How It Works

Steering

Just like the concept itself, the concepts behind programming this are fairly simple. First you’ll need some sort of steering function or class so your units can move on their own. The work involved in this depends on what you’re making the game with, but in a demo of this that I made, I used Unity and C#’s Vector3.MoveTowards() function.

Formation and Slots

Once you’ve got that, you can get to actually implementing coordinated movement. In its most basic state, you’ve got some sort of Formation object/class with any number of Slot objects within it. The Formation has a given center, although this can be a given Slot or just in-between all of the Slots, and the Slots are positioned where you want them in-relation to that center.

Putting Them Together

With all of this, now you just need to make each object use the steering I mentioned before to move towards their individual Slots in the Formation. By actively doing this (aka running your steerings in Update() functions), your units will not only get into a static formation, but whenever you move the center of your Formation, the Slots should move with it and then the units will move together to get to those Slots. It’s pretty simple, but it’s a neat way to have some good looking movement from a group of units.

Taking It Further

That’s all well and good, but when you get to higher-level programming, just this much won’t be enough for what you want to do. Here’s a couple of concepts from Artificial Intelligence for Games again for some ideas.

Scalable Formations

One thing you might want is to have the size of the Formation or the number of Slots be dynamic aka scalable. So for each unit/Slot you add to the Formation, you’d want to set it up so that the relative positions of the Slots would shift as needed. With this you can get things such as this example:

scalecircle

Multiple Steerings

Ideally, depending on your game, you’d want to combine the steerings units have to move towards their Slots combined with other types of steering. For example, maybe you want to combine group formations with Pathfinding, in which case you’d have the Formation center do the Pathfinding steering, and since the Slots should always be relative, you’ll be doing Pathfinding for the whole Formation. Or perhaps the units must do obstacle collision as well so they just do their best to steer towards their Slots. It all depends on your set-up, but these formations should be easily combined with other movement and steering types.

When To Use It

Obviously not all of this is applicable to all types of games, or even all types of games with enemies. However, you can see these techniques being used in games like the Company of Heroes series or the Age of Empires series. Generally you might want to consider using these techniques in RTS (real time strategy) games or maybe even shoot-em-up games. Any game where the movement and shape of a group of enemies can matter can be considered for this technique.

Visual Tech Demo

To help visualize the basic technique a bit better, I’ve created a demo of it in Unity which you can find down here. The basic controls are Left-Clicking to set the go-to position for the Formation and pressing Space to toggle the sprites for the Slots and mouse-click position.

References

My main sources of information for this post are Ian Millington’s Artificial Intelligence for Games, a textbook about a variety of game AI techniques, and a post on Gamasutra by Dave Pottinger. You can find the book on Amazon or basically anywhere you’d normally find textbooks and the Gamasutra post at:

http://www.gamasutra.com/view/feature/131720/coordinated_unit_movement.php

Coordinated Unit Movement