Jump to content
  • Advertisement
Sign in to follow this  
web_scripter

RTS - Unit Formations

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would i go about establishing formations. Would i have to make a class for each formation and assign the units to the class in a linked list, and then instead of moving the units i move the formation, and the formation places the units apropriately. Or is there a better way of doing this? cause if i do this then i would have to see if i'm moving a unit or a formation but i could derive it from a base class that handles the movement. That would solve that problem. So yah should i do formations the way above or is there a better way?

Share this post


Link to post
Share on other sites
Advertisement
I'm assuming here that your using OOP.

You could always have the formation as a child of a base unit class and have it overload the movement function.

Or have all units as parts of a formation and have a formation that takes only one unit.

Dragoncar

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragoncar
Or have all units as parts of a formation and have a formation that takes only one unit.

This is probably the best answer, I use it and it works well. It also saves a lots of network bandwidth or AI processing if you do both of those things using formation objects, but still has complete flexibility if you (or an AI) decide to take a unit off by itself.

Share this post


Link to post
Share on other sites
You could have a different class for each formation where the formation class would determine the position of the units within the formation. The formation can maintain a vector of pointers to units within the formation and maybe a unit holds a reference to the formation its within too.
When a unit is added to the formation it calculates the position of the unit and passes it as the destination point of the unit. When the formation is moved, a new destination point is calculated for each unit every frame and passed as the destination point for each unit.
This would allow a formation to split up if there were an obstacle in the way and then re-form on the other side (imagine birds or fish in a formation that split into two formations and then back into one).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!