Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 07, 2013 at 05:37 AM by clunk47 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Gsullyman · Aug 13, 2013 at 01:27 AM · rtsspaceflight

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Aug 13, 2013 at 01:42 AM 0
Share

What construct are you using to define a squadron - parent/child game objects, List/Arrays etc?

avatar image vexe · Sep 26, 2013 at 05:56 PM 1
Share

DEAR OP: If you're still alive, please tick an answer as correct, to keep the board clean and tidy and make everybody happy, if the answers weren't helpful, then we appreciate feedback. Thanks.

2 Replies

  • Sort: 
avatar image
4
Best Answer

Answer by vexe · Aug 13, 2013 at 11:30 AM

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][1].

[1]: http://www.youtube.com/playlist?list=PLcGWkWha2wFd5Azr14ZJjvfnAmUKM_3E7

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Narv · Aug 13, 2013 at 11:33 AM

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.

  1. 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.

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RPC Parameter Optimization 1 Answer

RTS Grid and Pathfinding 2 Answers

Best way to simulate Character Controller under Fixed Update? 1 Answer

What do I have to follow to create a good-looking RTS Terrain? 3 Answers

Camera rapidly changes it's position when the parent changes. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges