How to smooth and spread A* paths for an RTS
construct.net
construct.net
What I've learned is that A* is largely deprecated these days. Modern games mostly use "navigation meshes" for "any angle" pathfinding to address what is otherwise an np complete problem. The idea is that you generate a set of vertices across your terrain and compute the path from there.
One of the current leading experts in this is Daniel Harabor. His papers are brilliant
However, I did work on a number of popular open world racing games where a lot of NPCs were travelling across the map, often where no player was nearby. For these, as well as for visualization of travel routes on the map, we used a graph of the road network and A* with some simple modifications such as adding edges from the start and end point to the nearest points on the road network.
Having implemented A*-style algorithms occasionally, I was under the impression that by "navmesh" people mean a planar vector structure that can then be navigated using, for example, A*. As opposed to a grid data structure consisting of cells that can then be navigated using a pathfinding algorithm. I always saw A* as a strategy to find a path in any graph, and I saw navmesh as an example of such a graph.
Now it seems people are defining navmeshes as both a data structure AND pathfinding strategy, and by the same token are likewise seeing A* as both. This seems really confusing to me.
Have I been using the lingo wrong all this time?
This is also how many game engines, including Unity, implement their NavMesh queries.
Maybe they use it cause it's quick and easy, not because it's the most optimal?
Of course this does cover most of the cases, probably even for "space" games (which are often more akin to WW1/WW2 naval simulators).
> It’s not yet clear to what degree new algorithms like Anya and Polyanya can help improve the state-of-the-art in these areas.
Considering how Poly-Anya was sometimes slower than Anya (the non-nav-mesh version of path finding), it seems like the jury is still out as to whether this technique + nav-mesh is useful?
I could be completely wrong, I'm just looking at the results from the papers/slides you posted. It seems that A* still has relevance because it and modifications to it are still the fastest path-finding algorithms?
>The path algorithm works by following a LOS path to the target. If it collides with an impassable spot, it uses an Edge following routine to get around it. The edge follower moves along the edge in a clockwise or counter clockwise fashion until finding the destination spot. The destination is determined by Find_Path. It is the first passable that can be reached (so it will handle the doughnut case, where there is a passable in the center of an unreachable area).
https://github.com/electronicarts/CnC_Remastered_Collection/...
https://github.com/electronicarts/CnC_Remastered_Collection/...
(on a side note the comments are incredibly detailed, considering this is from 1993-95)
It was experiences like that which made be briefly consider a career trying to make better game AI.
It looks like a much more useful optimization would be to produce a simplified map that splits the "real" map into "connected regions" via chokepoints. Pathing on that simplified map should be orders of magnitude simpler than on the "real" one. That's the "high-level plan": go to region A, then to region B, then target is on region C.
Once you have a high-level plan, each unit only need to do the expensive pathing until their next chokepoint (or to the target, if they are on the same region).
This is especially relevant on dynamic maps that are continuously changing (e.g. enemy units blocking paths, or building structures, or fog-of-war that keeps being updated, or closing and opening doors). Re-calculating the high-level path every time for every unit, and throwing it away when there's a change, is too expensive. Much more economical to recalculate the high-level map once for everyone, and then do high-level plans + pathing to the next choke.
Rimworld has a video where they explained their Region system, which implements this: https://www.youtube.com/watch?v=RMBQn_sg7DA
The map in Rimworld is destructible though, so that sort of technique doesn’t quite work.
One thing I really liked was how chatty the enemies were. I think they claimed the Grunts would “act smarter” when Elites were around to command them. No idea if that was just marketing fluff though. Hard to notice either way, because there’s the confounding factor that the Elites are just stronger enemies so those fights would naturally be harder.
I’ve always thought it would be cool if the developers would take a “no cheating” approach — model what every unit has observed and require them to make a noise in order to share that information. It would add another dimension of difficulty — “highly trained” units could be modeled as able to communicate more information with less noise (and then add some units that just use hand signals or if it is sci-fi, psychics that can give orders silently).
https://alumni.media.mit.edu/~jorkin/goap.html
Really interesting stuff.
It appears chronologically dated at this point, but I'm not sure that anyone's made substantial improvements, given the lack of investment into single player games.
If I was trying to do AI for a game, I would suck down every link on that web page. Even if you think you can do better, this is a great bar to measure against.
It could just be updated. Terrain/building destruction events don't happen all that often in Rimworld, maps also aren't too big
Factorio Friday Facts #317 - New pathfinding algorithm :
Using the low level map for the heuristic on the high level one is neat. Making the high level algo resumable is also very neat. I still think they should be pathing “only to the next region” on the high level map.
I believe that's one of the reason LoL and Dota became more popular than any RTS.
A master of click work, will loose against the onslought of material of the Big E, in the long run.
Its mostly visible in the pros vs joes matches of BAR Players, in which well managed exponential eco allows a recovery from impossible situations, marshalling exponential growth against several weaker, though elo strong players at the same time.
https://www.youtube.com/watch?v=QuAPHw3DwMY
Its like watching BIG O N^2 beating Big O lin N to pulp, but in a rts. Blink and you miss it though. Its the infrastructure bootstrapping itself, in the back of the base.
You inevitably end up with strategic considerations in games with more than 2 teams (especially if the teams are not locked), but most RT"S" matches are not played in these conditions (probably because they are too fast for diplomacy, which is itself a huge chunk of strategy).
I guess "Macro" is Operations ?
I feel that Brood War embodies this part of Clausewitz quite well.
The single player mode (and custom maps mode) all do not really require micro'ing to be very fun.
The rest of the RTS world relentlessly pursued micro, of course. And the MOBAs that came of that are fine for what they are, but what they aren't is something I personally want to play.
It always surprised me that parts of the tech research tree in any RTS didn't seem to include smarter unit behavior as part of the stack. Paying in-game resources to off-load cognitive load is an interesting loop!
Partial credit is due to Majesty, which is the only indirect-control RTS I've come across. Old game, but still fun for what it was. I liked the idea.
And shout out to Achron which managed to weave freaking *time travel* into the gameplay !!
(It also has a single-player campaign where you slowly get to learn the more than 100 units and features.)
But BAR/Spring seems like it would fit you better (it's also the closest of them to TA, which is otherwise a bit old these days) :
https://www.beyondallreason.info/
(BAR used to stand for Balanced Annihilation Reloaded, while Zero-K used to be called Complete Annihilation.)
Persistent between games: Configurable building templates - one building command queues whatever you set in whatever arrangement, rotatable on placement.
Factory infinite repeating queues with waypointing including automated airlift ferrying for ground units if required.
Adjustable waypoints. Move, insert, remove waypoints without having to redo the whole set from scratch.
Plus I like the storage aspect of resource management and the titanic units. Not so sure I care much for nukes though...
The resulting algorithm bears similarities to Dijkstra's or A* (i.e. it is a sort of value iteration, see the "fast marching method") but yields a scalar field, whose gradient will give the direction of the optimal path at any point.
The algorithm can handle 100,000+ units path finding to their own unique destinations at 60 FPS. [edit: on a single CPU core]. The graph is processed once, and stores all possible paths (using near minimum storage)
Additionally, I can have additional preference weights in the graph so units can use paths that match their preferences.
Note: The video[0] no longer represents the look of my game, as I've moved on to isometric[1].
Regarding general multi agent path finding: There is a lot of literature around with respect to time optimal planning in MAPF both in robotics, and in adjacent fields.
[1] http://www.osrobotics.org/osr/planning/post_processing.html
[2] https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&d...
In a production environment you do want to eliminate the other processes.
So subtract two. Leave two free.
I made an RTS in C++ a while ago and was able to build paths for many units per frame on a fairly large map. And even if I couldn't, there's many optimizations I would have considered before threading, like only building a partial path based on portals. Or building a "bad" path and simplifying it on future frames.
Here's a great A* references with a bunch of helpful tricks: http://theory.stanford.edu/~amitp/GameProgramming/
You could merge large squares of open space as an optimization though.
And actually, depending on the connectivity of the fine square grid, pathfinding on it is pretty suboptimal too, because you're only finding paths that are shortest in Manhattan- or 8-connected distance (barring some fast-marching/Eikonal thing). If your units are really restricted to those motions then that's correct, but if they can move continuously then you're losing a lot of diagonals. So that's another argument for polygons.
No reading up, but somewhere there was a blog post by the programers and a reference to the paper
All an agent has to do is query their current spot in the graph and it will return a vector that leads them to the next lowest cost. This is useful if you have lots of agents going to the same location.
https://www.youtube.com/watch?v=BHcQ4JCj27w
The description of this video has a lot of good resources. I made it when I was a much much worse programmer though so I wouldn't bother actually watching the video lol.
[1] - http://www.gameaipro.com/GameAIPro/GameAIPro_Chapter23_Crowd...
Because multithreading introduces a lot of complexity, making it inflexible and hard to scale. Of course you would never do it if the code was fast enough to not have to.
I never had to consider it, I could generate about 16 complete flow fields per frame on a 512x512 map with no quadtree optimization.
It sounds like a nice way to learn webworkers, but I think you're always better off hitting the perf bottleneck first, rather than trying to design around it early.
Of course, that's more complicated, but you get collision avoidance as well. Probably better coordination than real-world vehicles. One may get weird results though, such as two units using a completely different path because that saves them two seconds, which may not be a good strategy in an RTS.
Which might be entirely fine if you want to make strategy focused on macro, not micro.
Some games have formations that are compact or spread that player can choose, some, like TW:Warhammer, have some units that are spread and some that are compact (in a game where you control only whole squads) and all of that have different drawbacks, compact ones are good for defending chokepoints, spread ones are harder to aoe etc.
That just becomes another aspect of the strategic and tactical trade-offs! As the commander do I want to space my forces out, reducing their vulnerability to artillery but potentially making it take longer for the column to bring a deciding volume of fire to bear once they reach the front, possibly feeding them piecemeal into the teeth of the enemy? Has the enemy favored more artillery versus less? Are these units needed in battle this instant?
Basically the classic Napoleonic dilemma of when to deploy the troops from column into line.
But yeah as you say, it totally depends on the game that is being made.
The AI Systems of Left 4 Dead - Akamaihd.net https://steamcdn-a.akamaihd.net/apps/valve/2009/ai_systems_o...
I've not been in triple-A games for many years, but I'm not sure I'd choose navmeshes today for an RTS style game over a large terrain - they tend to be static in nature (without attaching a lot of additional data to them, projecting dynamic obstacles onto them, re-weighting all the polys all the time, while making sure that the resolution is fine enough for this purpose or coming up with some vector field on top of the larger ones.... but no one needs to save RAM these days, do they... it's not 32MB of Playstation 2 anymore).
Edit: forgot to add that once you realise that A* is 'open ended' and that you drive it via the heuristic estimate, that can be anything, it becomes much much more suited to 'strategic' path-finding than what's normally envisaged described as 'A-to-B' path finding.
I wonder if a better solution would be to treat the whole group of units as one mega-unit, pathfind for that, then if the path for the megaunit is some factor longer than the straight collision-ignoring route, split it up into 2-6 squad-units. Or split the megaunit up into however many squad-units it takes to have a maximum of a dozen units per squad, pathfind for the squads with some collision avoidance, then do a more fine-grained process of calculating a path for each unit from its current position relative to its squad's center to the same position relative to the next point on the squad's path.
I never play this sort of game so maybe this is routine now, I dunno.
I wonder if they do something along these lines, or if they literally just treat the formation as a single unit and path for that?
Probably true, but this seems like a massive resource utilisation for an RTS game.
Construct seems to have come a long way since.
(Hi tigerworks, bornemix here from the CT forums)
Dragoons are particularly absurd, because their collision box changes as they walk, and they’re huge, so they block one turn and unblock the next, and block again, triggering the “full reroute” with even a trivial number of them despite congestion appearing pretty light.
I think this dumb collision resolution strategy would have been mostly fine if they had handled the ABA problem and waited longer in that scenario (or planned to replan for dramatic differences in route lengths after collision-rerouting)