So, here’s the deal: I’m working on a strategy-type game where individual units are grouped together into “squads”, like Star Wars: Empire at War, Battle for Middle-Earth II, or Age of Empires III. My current built-in pathfinding solution isn’t great, but it gets the job done.
However, my squads keep getting stuck in places where they don’t quite fit. The pathfinding algorithms hug corners, which causes units on the outside of the formation to get stuck on walls. (My current solution, allowing units too far away from the main group to pass through walls, is less than ideal) In addition, for situations where the whole group is too large to pass through a valley or corridor, I’d like them to squash themselves together into a line, even going single-file if they have to.
To make matters even more complicated, these squads aren’t all the same size. Some of them will have more units than others, and for some, the units themselves will just plain be bigger.
I guess my question is where would I even start to tackle this problem? I’m willing to start over with the unit movement if I have to. I’d like to avoid using third-party libraries, as I eventually plan to make a game using these same concepts outside of Unity, so I need to know how to do this stuff.
I would create some kind of “boundary” that you would put over the squad. Then use the movement script to check for if the boundaries for the squads in stead of what your doing. Then you could use a script that changes shape and form whenever needed.
I don’t think this will really work. I think I’ll run into too many circular dependancies like this, i.e. need to calculate the boundary to find my unit’s position, need to calculate unit’s position to calculate the boundary…
Unfortunately I don’t have a lot of money to spend on books right now, but maybe some other day. Looking at the description, it seems like it’d be way over my head, anyways; I’m kind of an AI noob.
Edit: DERP. Just realized I could probably use flocking algorithms to get the formations I’m looking for. I’m not after perfect squares, just a reasonably cohesive blob.
If that’s the same article I’m thinking of, I can save you some $$$ and give you their insight.
The squads getting stuck on sharp edges was the result of a misalignment between the objects and the pathfinding grids, as illustrated in the above picture. The nodes sometimes led them right into a building’s corner. They synched the two in C&C 4.