# Thread: Game theory: Putting units in formation

1. 23
posts
Registered User

## Game theory: Putting units in formation

OK, I'm trying to make a game and something I want to implement is a simple way of putting units in formation.

I thought about 2 ways of doing this:

1) Putting them in quadrants and separating them evenly across them.

Or 2) Making the distances between them same:

I have it down in theory, but not really sure how I can do it coding wise.

Any ideas?

PS. Formation AROUND the leader, or red circle.

EDIT: The more I think about it... I should just switch to tile-based...
Last edited by zuperxtreme; May 24th, 2008 at 07:46 PM.

2. You will be better off in a tilebased or gridbased environment. Grouping/formation is one of the game theories, that is often used with path-finding algorithms to give a good feel to the game. Formation is done with many different algorithms, and most programmers have their own approach to it. If you want to understand formation, then though it will seem very different, start with a carousel example...

3. Try messing around with this:

var vel: Point = new Point(target.x - pos.x, target.y - pos.y);
var velLength = vel.length();
vel.Normalize(characterSpeed);
if(velLength < 10){
vel.x = 0;
vel.y = 0;
}

and when updating the character increment it's position by the vel aka velocity.

Do that for each of the units. You'll notice this is just vector math.

Also if you want to study it. Just look at Boids. It's a group of algorithms for flocking behavior. If you study it long enough it should make sense. You'll end up with something like:
http://www.assaultwars.com/flash/AS3Boids/AS3Boids.html

It's a simple set of algorithms but it takes a lot of understanding to use them right.

//here
//also since people doing AI ask about steering it's crucial you understand the dot product of two vectors.
and here's the algorithm basically once you understand dot product.
Last edited by Sirisian; May 25th, 2008 at 02:37 AM.

4. 23
posts
Registered User
Originally Posted by Sirisian
Try messing around with this:

var vel: Point = new Point(target.x - pos.x, target.y - pos.y);
var velLength = vel.length();
vel.Normalize(characterSpeed);
if(velLength < 10){
vel.x = 0;
vel.y = 0;
}

and when updating the character increment it's position by the vel aka velocity.

Do that for each of the units. You'll notice this is just vector math.

Also if you want to study it. Just look at Boids. It's a group of algorithms for flocking behavior. If you study it long enough it should make sense. You'll end up with something like:
http://www.assaultwars.com/flash/AS3Boids/AS3Boids.html

It's a simple set of algorithms but it takes a lot of understanding to use them right.

//here
//also since people doing AI ask about steering it's crucial you understand the dot product of two vectors.
and here's the algorithm basically once you understand dot product.
Thanks a ton. It looks like I have more work ahead of me than expected.

Cheers!

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
 About kirupa.com