Skip to main content
GameDev.net gamedev.net
🔒 Locked

Unit groups in a RTS

Started by Calin Dec 22, 2024 at 9:13 PM 11 replies 4.4k views
Original Post
Calin
Calin

In Starcraft when an AI Player is attacking you what you have is a thin constant stream of units arriving at your base. What does it take to build an alternative? In Total Annihilation the AI player waits until a group of units has pilled up and then attacks. If the attack is unsuccesful the remaining attacking units retreat. The Total Annihilation approach probably works the same as Starcraft except the retreat. The maps layout in Starcraft probably causes the units to spread like a stream. How does a typical RTS AI player attack work? Select all combat units, Attack-move selected combat units to the enemy base?

My project`s facebook page is “DreamLand Page”
frob
frob

There have been a lot of variation in games over the decades, so there really isn't a “typical”.

Some games have mini-formations, like a group of 5 soldiers may cluster and move as a group taking a single tile. Some games have included commands to keep a formation, so you could place them in a particular ordering and they'd advance at a uniform speed based on the slowest units, such as creating a line of soldiers and they'd hold the line as they travel or attack or retreat. Some games have included automatically-issued commands causing units to scatter or evade defensively, or standing orders to hold position or not return fire rather than evade or counterattack.

The logic is typically implemented as nested state machines. Logic may be to move toward a target, patrol between points, react to getting attacked taking any of various sub-choices depending on what is attacking, and much more. The limit is usually more about development budget and time than it is about creativity, as designers with unlimited time and money could devise a tremendous number of commands and flows.

There are also hundreds of articles over the decades with all kinds of explanations of grouping behavior, flocking behavior, pathing together vs pathing independently, treating clusters as a single unit for pathfinding instead of a bunch of tiny objects all doing their own search, and much more.

Calin
Calin

There have been a lot of variation in games over the decades

I see what you're saying. Age of Empires 2 had formations. That's a bit more intricate than just select and move everyone to the enemy base.

My project`s facebook page is “DreamLand Page”
frob
frob

Even that, “select everyone and move to the enemy base”, do you want them to stay together, or do you want some type of strategic organization?

Do you want the fastest moving units to arrive first, before the slowest, or do you want them to arrive as a cohesive whole? There are merits to both.

Do you want new units to arrive and attempt to join the formation as a cohesive whole, or just wherever you clicked?

Do you want newly formed units to replace the ones that were lost in the formations, or to meet at some other waypoint?

All are good ideas, and all require implementation.

Calin
Calin

Even that, “select everyone and move to the enemy base”, do you want them to stay together, or do you want

If it's the most basic scenario ever there's just one way to do it.

My project`s facebook page is “DreamLand Page”
JoeJ
JoeJ

Calin said:
If it's the most basic scenario ever there's just one way to do it.

That's the grand picture, the simple idea on top, the lower frequencies, the highest level abstraction, or however you call it.

But below that lurk the depths, the details, the complexities, and with it comes the opportunity to add depth to the game.

At least that's how you can think about it. While in reality it's mostly just a pile of unexpected work, i would say.

Anyway, what i try to say is that your quote does not hold - if we take a closer look.
Even if all my units are supposed to just walk to the enemy base, there is never only one way to do it, if there are multiple units.
As the player i will observe their behevior. I will notice how they prevent collisions with each other etc., and i will judge if it looks natural or silly.
Ideally i'll enjoy the observation. In german they call it ‘Wuselfaktor’, meaning to watch hundreds of cute tiny settlers building a village or having some daily routines. It's important players find this satisfying to watch, and i guess the same also applies to other top down genres like RTS.

Your latest video showed good progress on this. The behavior looked much smoother, and no more visible ‘silly computer AI’ corner cases.
But improvement is still possible, and will become necessary once better graphics expose more details.

Now i see two options to continue:
1. Decide about features you want. E.g. if you want clearly defined formations, work on that. E.g. let them form a N x M grid pattern and they should keep that in shape while moving along a common path.
2. Don't implement such features yet, but instead improve the default behavior so it looks more natural and units appear smarter. Eventually you'll have tuning parameters to define the behavior, and simply changing those parameters will affect if they walk in a straight line if they have a commonm goal, or if they form a blob shape. (If you have terrrain, this should also affect those things.)

You said you want to make a generic RTS AI, iirc.
But sooner or later you get down to the depths of all those details no matter what, and at this point it becomes easier to make just one specific game instead some genric default AI supposed to serve any game design.

Calin
Calin

That's the grand picture, the simple idea on top…

…But below that lurk the depths, the details,

You can have a simple implementation too it's not just about ideas. One thing can have different levels of complexity.

My project`s facebook page is “DreamLand Page”
JoeJ
JoeJ

Calin said:
You can have a simple implementation too it's not just about ideas. One thing can have different levels of complexity.

Well, yes. But it rarely works to keep it simple. People say ‘don't be stupid - keep it simple! :D’.
But the reality is: You start with complex solutions. And only after you became a true master working on those, you become able to replace the complex with a simpler and better solution, where possible.
Simplicity is not something you can just do. It's the result of optimizing former complexity, and creative ideas are often needed to get there.

Ofc. this only applies if the given problem is difficult. If it's a trivial problem, you can google for the common solution und use just that.
Probably complex behavior of many RTS untis is neither trivial nor simple.

It's like in physics. They can predict the trajectories of two stars affecting each other, but adding just one more star destroys the simplicity, causing unpredictable chaos.
Likely you can't avoid the chaos either, and probably you shouldn't anyway, since it is a source of ‘emergent behavior’.
But usually we need to keep the chaos under control somehow, meaning your units behavior should still look reasonable and natural even in unexpected / crowded situations.
It helps to have debug setups to create such exaggerated difficult / impossible situations.

Calin
Calin

You can have a simple implementation too it's not just about ideas. One thing can have different levels of complexity.

But my purpose here is to learn. I'm not going to start teaching a senior programmer about RTS games.

My project`s facebook page is “DreamLand Page”
Calin
Calin

JoeJ said:
Well, yes. But it rarely works to keep it simple.

It's buggy, short sighted but it works. )

My project`s facebook page is “DreamLand Page”
JoeJ
JoeJ

Calin said:
But my purpose here is to learn. I'm not going to start teaching a senior programmer about RTS games.

Learning only brings you to the point of current state of the art. After that point your contribution begins. You might come up with something new, and future senior programmers might learn about your former ideas. : )

I mean, we might run into some misunderstandings here, and philosophy won't answer your question.
But your question is just too broad, so all the senior programmer can do is listing up some options to illustrate that different people and games came up with different aproaches.
If you would narrow the question down to something like ‘Ok, so i want my units to move in formations like the Romans did. How can i implement that?’, people could give some actual proposals i guess. But actually it's too broad.

Calin said:
It's buggy, short sighted but it works. )

It's buggy, but it works regardless? :O
Hehe, my prediction: flaws which feel acceptable right now will require a fix in the future.
And implementing all those fixes will increase complexity. And it may pile up to the point where the desire grows to replace the pile with something simpler.
So you start out simple, which is nice. But then it becomes complicated and messy, which sucks. Finally you replace the pile of hacks with something truly simple, robust, and general. But you could not come up with this final and good solution from the start, since you did not yet know about the unexpected flaws and problems back then.
That's how it usually goes. In my experience at least. Doing it wrong is part of the process, and senior advice has only minor effect on this natural progression.

Calin
Calin

JoeJ said:
Learning only brings you to the point of current state of the art.

If you go all the way yes. But that's just one possible final station.

JoeJ said:
It's buggy, but it works regardless?

There are all sorts of bugs you know that.

Severe bugs that stop your game from running (or make your game run abnormal) or less serious bugs that are unpleasant to the eye, but the game keeps running.

My project`s facebook page is “DreamLand Page”

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.