How does StarCraft II's pathfinding algorithm work

2D path finding - find smooth paths

I tried to implement simple path finding, but the result is less than what I was trying to achieve. The thing is that in games like Starcraft 2, units move in all directions while in my case units only move in at most 8 directions (Warcraft 1 style) as those 8 directions go straight to the nearest available nodes (they move from one tile to the next adjacent tile). . What do I have to do to get the result like in Starcraft 2? Reduce tile size?

In the picture you can see a horizontal line of rock tiles as obstacles and the path found as green tiles. The red line is the way I want to go.


For a good path finding algorithm, using A * would probably be a good idea for a simple game that doesn't require a sophisticated, efficient, or effective path finding where characters simply move towards a target by figuring out the direction of the target should be sufficient be.

You can create a visibility graph from the vertices (what other points are visible from each point) and then do A * on the graph. This works because the shortest path is always in the visibility diagram.

Shrinking the tile size can help you.


further reading

EDIT: I like @ MarkusvonBroady's comment.

"It's actually about smoothing paths, not finding them. The path found in the picture looks fine."


By @MarkusvonBroady

I did a search and I find the following (these can help you)

For example, starting from one end of the raw path, you can remove that the segment formed by connecting the points of and does NOT intersect a wall. If you keep going to the last segment you will get an easier path.

Not only will this smooth out the path, but it will also remove some useless points such as: B. 3 consecutive segments of a straight line.

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.