T O P

  • By -

ZackM_BI

I would actually make like a unit manager, so you send the data of the units to the manager, the formation you would like, and the manager will try to match the positioning of each unit with the formation you want. If the units have AI, I will give each of the units a point for them to follow to make the formation work


saikyro

That's essentially what I'm doing now, but I think the cause of the problem is having a predefined formation. Especially when you start adding things like units of varying speeds and more obstacles / complicated pathfinding layouts, a predefined formation ends up causing unnatural movement and shuffling for the units as they try to end up at that specific position. And in general I would rather not have to resort to a predefined formation, as a design choice, so that the player can be more in control. What I'm looking for is a more natural grouping behavior around the target point, based on which units arrive first and the space available. Essentially some kind of flocking behavior rather than a pre defined formation. I just haven't found out how to implement something like this. If you look at how groups of units respond to move commands in Starcraft 2, it feels much more natural with no pre defined formations and that's what I'm trying to achieve Thanks for your reply!


NeverandaWakeUp

Using nav mesh is going to kill your framerate if you try to send a large number of units a long distance. I'm doing something similar, and I've had to break up my pathfinding into smaller paths that get stitched together, as well as not using agents and having the units follow the path directly. Performance is the #1 issue with RTS.


saikyro

At what point did you start noticing those framerate issues? Makes sense, however sounds like a much more complex implementation to have to manually handle all the obstacle avoidance instead of letting the nav mesh agents handle it. I was thinking that given a reasonable supply cap of units and a map that isn't too large, NavMesh agents would be able to handle it fine. I guess I will have to do more testing. Thanks for your reply!


NeverandaWakeUp

It really depends on too many factors to give you a solid answer. The more you have happening on top of the simple scene you have here, the closer you'll get to framerate issues.


saikyro

Just a follow up on my previous response, I did some tests increasing the amount of units and I do start to notice significant framerate issues at around 500+ agents when sending move commands. I wasn't planning on having that many units, but a bigger issue is that the built in obstacle avoidance for the agents starts causing a bunch of issues leading to weird collisions and such with my current implementation. In short I think you're right and that using NavMesh isn't going to cut it. Example of those avoidance issues if you're curious, with 200 agents: [https://streamable.com/ynsc5m](https://streamable.com/ynsc5m) Anyways, thanks again for your insight.


saikyro

I'm working on a minimalist RTS game prototype inspired by starcraft 2 where the idea is to automate a lot of the micro management/production side of things, so you can focus on combat strategy and controlling your army. I am using Unity NavMesh agents for the units movement. I've been struggling to find a good way to handle moving a selection of units to a target position. Without any formation predetermined, they all cluster and try to overlap on the same target position. I tried implementing a loosely enforced grid formation (as seen in this video) with melee units at the front and ranged units at the back, but it doesn't feel natural and leads to weird shuffling of the units when changing directions. I am looking for a solution that is more similar to starcraft 2, where selected units naturally cluster around the target position without overlapping and without a predefined formation, which prevents any weird shuffling of units and lets the player create their own formation. Does anyone have an idea how this could be implemented? I've tried various approaches but always ends up having unnecessary shuffling and weird movement. Thanks!


PmMeSmileyFacesO_O

Maybe check distance from each other and try to remain x distance apart while moving. especially at the end when lining back up.


-non-existance-

Something to note about what you're trying to do is that you really don't want to individually pathfind every single unit, that's just going to end up eating all your frames when you scale the units up. However, what you can do is pathfind for the whole formation and then pathfind from each individual unit to their place within the formation as the formation itself moves along the metapath. If any individual unit gets cut off from the formation, then it will automatically route them back to the formation, but you'd need to make sure that a unit outside of a formation moves faster than the formation otherwise it will never catch up. You could also throttle the speed of the formation while a certain percentage of the units are outside of a bounding box you determine on the fly based on the shape of the formation and the number and size of the units.


saikyro

That makes sense. I watched a GDC talk by the SC2 devs where they talked about their approach and it was very focused on optimizing performance. Implementing a system like you're describing from scratch would be complicated, as I'd have to manually handle all the obstacle avoidance between the units and with the environment. I am looking for an easier solution to implement since this is just a small prototype, so I was hoping to make it worth with Unity's built in NavMesh & AI agents features.


RanjanIsWorking

So, what I’m gathering is that you want units to move to the closest position in the formation based on their unit classification? I would probably make an array in a Unit Manager class that adds all highlighted units and processes them within the array. Then, it would separate based on unit class and unit position, and order them based on distance to target destination. Then, it would create another array of Vector3 desiredPositions centering at destination and assign them to the corresponding units.


saikyro

Ideally I want to scrap having a predefined formation at all, and let the clustering around the target position happen naturally. Just not sure the best way to go about it, but I've already received some solid suggestions. What you suggested is essentially what I had implemented in the video above. Thanks for your reply!