How to make rts squadron groups?

Hey, I’m trying to make a RTS space game much like Star Wars Empire at War. The problem I am running into is the star fighter squadrons. I am trying to figure out how to make the individual ships into squads. What I need them to do:

  • When you select one fighter it selects the whole squadron
  • Fly in formation
  • Adjust formations when a unit is lost

Any help wold be greatly appreciated!

Show us what you came up with so far. I don’t know what solution are you expecting, but I’m assuming you’re just looking for ideas.

But basically you need some class to hold your squad members:

public class Squad

Inside that class:

you could use a list of your squadrons/soldiers/warriors

public List<Soldier> members = new List<Soldier>();

you could have a GameObject that will act as the Squad in the game
so in your constructor you could pass in a list of squadrons
so then you parent them to that game object, so that when the object move, the children
will move with it.

an enum to represent your formation

public Formation formation;

Where Formation is something like:

public enum Formation { Square, Rect, Triangle, Circle, etc... }

couple methods, like:

public void ChangeFormation(Formation newFormation)
{
    // make a switch statement on the new formation
    caes Formation.Square: 
    // do something to change their setup to a square shape
    // something like messing with their transforms, start by taking the no. squadrons you 
    // have in your squad, for ex 4, so you loop over 4 times get each squadron and 
    // position him with a specific offset... it would be easier if you made a function
    // that deals with your 1d list as 2d, or use a 2d list (I prefer the former method),
    // that way you loop over its
    // rows and cols and position each soldier...

}

perhaps something like:

public void Notify_UnitDown(string unitName)
{
  // find out who got killed, loop over your list and check names
  // take him out of your squad
  // you could then perform some checks to see what the squad's current formation is
  // and what their next formation should be, you must pre-set this bevaviour by 
  // yourself. like if they were 4 and 1 got killed, maybe you would want the remaining
  // 3 to stand in line?
}

Then you got your squad moving:

public void MoveTo(Vector3 newPos)
{
   // you need to find a way to choose a leader to your squad, so that you could choose
   // him to move, and make the others move with the same direction and the same distance
   // for n % 2 != 0 squads, like 5 members or 3, you could pick the one in the middle
   // compute the dist between him and the newPos, get the direction, move him and 
   // his other teammates according to that dist and direction...
}

I think you can select your whole squad by attaching a collider to it, and when the player clicks on it you highlight all squadrons or something…

void OnMouseClick()
{
  foreach(var member in members)
    member.Select(); // just highlight him, show some hud, healthbar, name, etc
}

Hope that kinda helped, you can’t really expect something better, because you must come up with something by yourself and shouldn’t depend on others from the start. Good luck.

[EDIT]: Just came across this.

Going off of what little you provided, i’d say:

1.) As getyour411 mentioned, how are you setting up the squadrons?

If you are using lists/arrays: Each unit most likely has a management script on them, correct? So you can have a list of the squadrons they are in (or if only 1 allowed, a single variable). If that variable is null or 0 or some value you decide, then they aren’t in a squad, if they are, then you probably have a game manager script that keeps track of all the squads and who is in them somewhere. Just make a cross-script call to the game manager and get a returned list of all the other objects in that squad.

If you are parenting all squads to a group (which would also make their squadron movement different than my answer below) then you would select all children under the parent node.

2.) This is a bit more difficult, that depends on what you define as “formation”… is it a box… how big is the box? RxC size set? is that box dynamic in size. so if you have 4 units is it 2x2 and if you have 9 units it’s 3x3… or is it always a minimum of 5 units in a row and then start the next row? Or hell, is it a V shape formation?

When you move to a location, are you using something like a navmeshagent for AI… or are you using graph nodes… or are you doing it yourself because it’s in “space”?

Chances are you want to go to a point… so set all units to a point but depending on how your formation is, you may want to make their endpoint an offset of the main point so they don’t all try to walk to the same point and collide.

3.) once you figure out #2, you’ll be able to do #3 pretty easily.