Calculations for A* Pathing

So I’m working on some A* scripts for the pathing in a tower defense game I’m making, but I’m not sure about the best ways to approach some of it. One thought I’m having now is if it would be a good idea to do the calculations for the path on the server, which will be updated every time the player places a tower, and then fire the client with the set of waypoint nodes to actually move each individual enemy through the nodes and then the client will handle the actual MoveTos.

Does this sound reasonable?

Is the path going to be static that the enemies go through? If so, there isn’t any need to use A* as it would be senseless to calculate the shortest path that enemies would go through if it’s always the same.

The enemies are actually trying to traverse a square gameboard that the player will be placing towers on top of, so the enemies have to figure out the most efficient path every time the player places a new tower. If the path is blocked, the enemies will begin attacking towers to create a path.

Oh okay, I see. Then your method seems to fit this well. You would want to definitely calculate the shortest path with A* on the server, and you can do tweening and animations on the client side. Be careful with how often you call A* as it is fairly expensive, but I think if you’re only making the calculation when a tower is placed, you should be fine.

1 Like

Yeah, originally I was going to recalculate the path for every enemy, but I saw that would be a nightmare so I realized I could just calculate the path once, use it for every enemy, and change the path when a tower is placed.

Yeah, for sure, I think your current idea won’t be a problem for optimization. I like the idea a lot, its unique for a tower defense game.

1 Like

Thanks! The idea is based on an old Warcraft III map that I loved playing. I hope I get a finished/polished product up and running.

1 Like