Monday, March 19, 2012

A* Lag and Group Disagreement

I haven’t posted in a while but here’s the update of how I’m doing. As I said before I’m the sole programmer in the group so I have been designing the programming structure and programming a lot and have done a lot of problem solving. I decided to do A* for our game since our game is a top down shooter and there will be waves of enemies closing in on the player and his elite military squad. The game has some dead ends and it will be difficult for steering-behaviours to steer around the dead ends. We also want the enemies’ movement to constantly moving towards the player cleverly (thus it will need the shortest route).

I had an disagreement with a fellow group mate as he kept telling me to use steering behaviours and not A* because he thinks A* is wrong and out dated, but with my horrible explanation skills I had a hard time explaining to him that Steering behaviours wouldn’t take the most efficient route to the target and steering behaviours may get stuck in dead ends or go the wrong way in in our type of map. The enemies need a path generator to get out of those situations and a good enemy script would use both steering behaviour and a path generator. Unfortunately this disagreement caused some delay in the production of our game and the group’s motivation had been damaged.

Even Starcraft uses it (images taken from http://www.teamliquid.net/forum/viewmessage.php?topic_id=132171):



Anyway, I dug out my A* code I coded last year in second year and threw it in the game and it worked beautifully. Only problem was, since our game has waves of enemies (I coded it to have a maximum of 100 at a time), the game started lagging whenever the enemies needed to generate a new path. I thought for a while and I came up with a solution (which I haven’t coded in yet since I’m coding in other features for our game) which was to multithread the A* path generator. This way, when there are delays when generating a series of paths for a series of monsters it wouldn’t affect the other elements of the game.

Here’s a screen shot of my year 2 A* program:

PS: I just wanted to say, another fix I thought of would be to use swarm AI and steering behaviours to avoid obsticals and then use A* for the lead unit in the swarm, the rest are following the lead this way I don't need to keep generating A* paths but I wouldn't be using this because of time and it doesn't fit our style of game play, the enemies should swarm together as a group, instead individually move towards the player and his squad.