RTS Formations

Blitz3D Forums/Blitz3D Programming/RTS Formations

boomboom(Posted 2006) [#1]
Any idea how todo RTS style formations of units? Think something like in the Total War series, or age of empires etc. Where a selection of units will go into formation.

I have been thinking this one over and havn't 'seen the light' yet on how todo it.

There are some complications that are confusing me. If a unit dyes, the rest in the group will reform the formation in the most efficiant way to plug the gap for example.


Shambler(Posted 2006) [#2]
I would store the formation pattern in an array or list of types where each element/type describes a position in the formation.

You could also store whether or not each position was occupied by a unit and if not select a unit to move itself to that position and join the formation.

Not quite sure what you mean by 'plug the gap' and I have a feeling this may have several possible solutions or have no meaning at all depending on the shape and position of the formation.


Jams(Posted 2006) [#3]
You could give each unit in the formation an index number, and then associate an offset with that index number. For example, for a queue style line, index 0 would have an offset of 0, index 1 would offset -5 on Z, index 2 -10 on Z and so forth.

That would make it relatively easy to change formations on the fly, because each unit retains its index number, and just recieves a new offset.

Also, to 'plug holes', you could adjust a units index number to fill the game. For example if unit with index 3 dies, unit with index 4 changes its index to 3, getting a new offset position... and so on along the queue...

Hope that makes sense, i might have to draw a diagram for this one....


Tom(Posted 2006) [#4]
How about building formations from 'row' types

A row would store a start & end position, and a unit count. Then simply assign your soldiers to the rows until the're full. Draw the soldiers evenly spaced out between row start & end.

If some of a rows soldiers were to get killed, you just space out the exisiting rows soldiers accordingly, and if they reach a low threshold count, then move some soldiers from another row to the one that needs bolstering e.t.c

Am I on the right track? :)


John J.(Posted 2006) [#5]
I give each unit a FormationX# field and FormationZ# field. These specify the unit's formation position relative to their leader's position.

Then, FormationX and FormationZ is just calculated for each unit to line them up in rows and columns:





This is how I calculate FormationX and FormationZ:


This method works well as new units are dynamically added to the formation, but not so good for filling in gaps when units are destrroyed.


puki(Posted 2006) [#6]
That looks a bit like my tank game.


_Skully(Posted 2006) [#7]
I had a game called GalaxyBlitz where the formations were created dynamically, by formula... this way no matter how many units joined the formation it would expand accordingly... in this game if a lone ship approached within a certain distance of a formation it would join and the formation would adjust to accomodate... units would always "try" to be in formation... they would use smoothed movement to try to get to where the actual location should be. Indeed even formations combined when they came close enough.


OJay(Posted 2006) [#8]
that: http://www.red3d.com/cwr/steer/gdc99/ helped me a lot!