# Using A* in an RTS game

This topic is 2812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've implemented a working A* algorithm in an RTS game I'm making, but I have a few queries on improving it.

Firstly, to fix the jagged movement I'm going to iterate between tiles to create straight lines between tiles which can see each other. This would involve drawing a line between two tiles and using Bresenham's algorithm to determine which tiles are on the line and if any of them are impassable. Is this the best way to smooth out the A* path?

Secondly, I'm unsure how to actually implement the pathfinding into the gameplay. Currently, if a unit is given a move order, I will generate the path every frame and move towards the first cell in the path, though of course this is very costly if you're moving lots of units at once. However, if I was to only generate the path when the move order is given, any changes in the game world (such as adding new structures) would be ignored by the units and they would path through them. What is the best way to solve this?

Thirdly, if I have a bunch of units selected and I ask them to move towards a point, they will all collapse on top of each other. A way I could solve this is by using flocking AI, but I don't know how well it would integrate with A*. This video is an example of what I want to achieve.

I'm asking quite a lot, so thanks for any answers you can give!

##### Share on other sites
1) Yeah, if you game supports it, move as directly as you can to the farthest visible node on the path.
2) Another method is to only repath if you attempt to move to a blocked square. This can lead to some bad behavior, of course. Often, you just have to split the difference.
3) Don't use a billion zerglings as your guide. James Anhalt of Blizzard did a GDC AI Summit lecture on how he did this and it isn't necessarily for beginners. Options include station-keeping (i.e. formations) and local steering for collision avoidance (i.e. simplified flocking rules).

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 23
• 38
• 75