How to do starcraft 2 pathfinding?

Started by
3 comments, last by TheComet 10 years, 5 months ago

I've been trying to figure out how to implement something like the pathfinding in Starcraft 2. I'm not looking for all the sophisticated features like flocking, queueing, etc. In fact I like how in Starcraft 1 the units would interfere with each other. But I do want a path finder better than that used in Starcraft 1.

From the Google searches I've done the various answers have something to do with A* over a navigation mesh and/or dealing with some kind of "visibility graph". But I've gotten somewhat conflicting or unclear answers on what I should do.

One thing I keep encountering has something to do with doing A* over a navmesh. And then use funnel to straighten out the path.

An older post http://www.gamedev.net/topic/597457-pathfinding-in-a-space-based-rts-game/ has an answer that says "Starcraft II uses a constrained Delaunay triangulation of the map terrain and buildings to produce a navmesh; A* with a funnel filter is used to path along this mesh, taking into account unit radii; then local steering and collision avoidance layers are added on top of that"

What exactly are the nodes of A* on navmesh? I don't see how any choice of nodes would allow A* on navmesh with a funnel filter to guarantee the path is optimal. But Starcraft II seems to not have the problem of A* going the "wrong way" around an obstacle because of a "shorter" pre-funnel filtered path.

How does Starcraft 2 pathfinding deal with the fact that the units are discs with a finite radius and not points when dealing with corners? And how does it deal with dynamic obstacles like idle units? Units are discs not polygons so treating them as part of the navmesh shouldn't make sense right? And how does pathfinding figure out that big units won't be able to fit through a far away narrow space. For a new buildings added does Starcraft 2 rebuild a new navmesh?

I'm looking for some gritty detailed explaination and not the generic super high level overviews that I've seen typical in search results. It sort of boggles my mind that there isn't a single source detailed explaination tutorial on the basics of the stuff. There is so much stuff out there I don't know what to look at and what to ignore.

If it matters I've already looked at Amit’s Notes about Path-Finding. I've heard of but not read Computational Geometry: Algorithms and Applications. And a blog post about a AI navigation presentation at GDC 2011 mentioned that Starcraft 2 uses a constrained delaunay triangulation for a navmesh. Although the blog post mentions Boids steering and "horizon analysis".

I really wish that guy ApochiPiQ who I quoted above knows the detailed answers to everything and obsessively answers this question.

Advertisement

Well, I am no expert but I actually have pondered this myself and the following are my conclusions:

And how does it deal with dynamic obstacles like idle units?

Well this is easy, and you answer it yourself with 'boid steering' but I will explain that further. So each unit has some kind of inner area of influence and an outer area of influence, see my mspaint picture:

[attachment=18170:Ultralisk.png]

Now one can, using math, get a value of 0.0 - 1.0 of your position between those area of influences! So using this 0.0-1.0 value you can slowly steer the units steering vector away based on how close you are to another units inner area of influence. E.g:

[attachment=18171:Zergling.png]

Now buildings can easily mark A* nodes as closed \ open on demand with little performance impact and if A* can't find a way out it just gives back the path up until it deemed the end point impossible to get to.

What exactly are the nodes of A* on navmesh?

Well nodes of A* are generally just a grid representing passable \ not passable terrain and that can be enhanced with a navmesh that basically says all of this is a node and matches an area precisely (or more precise than a grid)...hang on there is an article I read about this a few years ago:

http://www.ai-blog.net/archives/000152.html

There you go! Have a read of that it should answer the rest of your questions I think. Digest that information and ask more!

Engineering Manager at Deloitte Australia

Probably stating the obvious here, but I've used the two libraries recast navigation and detour to reproduce StarCraft II pathfinding before. It may be worth checking out, rather than re-inventing the wheel: https://github.com/memononen/recastnavigation

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty

Hi.

You could make a grid and in this grid each cell is linked to its neighbours cell,

each cell contains a cost, this cost is the units radius and how far it is from the target cell.

you could even create a second grid of boolean values for building if boolgrid cell == true then its blocked path around it.

and use A*;

here is a good link.

float grid[100][100];//this could be where all objects live to instead of a float use a class structure.

bool blocked[100][100];

Link

@ankhd - Grids are memory expensive and don't deliver accurate results when compared to a navigation mesh.

What exactly are the nodes of A* on navmesh?

Let me shed some more light on this question.

The nodes of A* on a navigation mesh are the vertices of the navigation mesh. When searching with A*, you assume the navigation mesh is a waypoint graph, because due to the convexity of each polygon, you know that each node is directly connected to every other node within the polygon, so there's absolutely no difference between a search on a navigation mesh and a search on a waypoint graph.

This article explains it very well.

http://udn.epicgames.com/Three/NavigationMeshReference.html

The only difference between a navigation mesh and a waypoint graph is the vertices of a navigation mesh hold information about an area rather than a single passable point. After the path has been found, the next step is to apply a funnel algorithm to simplify the found nodes into a more direct path.

http://digestingduck.blogspot.de/2010/03/simple-stupid-funnel-algorithm.html

I recommend reading through the documentation of the two libraries recastnavigation and detour. They are documented on CritterAI's website: http://www.critterai.org

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty

This topic is closed to new replies.

Advertisement