Monday 28 June 2010

Head up display

I managed to get a lot done this weekend. Not that I got any more time than normal but for a change most things worked first time as I had intended.

I wanted to check how much ammunition was left before being able to shoot. That inevitably led on to how I was going to display that to the player.

The ammo display allows for different magazine capacities and changes colour when the total carried gets low.

I also wrote the code to be able to reload including the sound effects and to be able to change weapon. This sounds simple but remember it has to happen over a period of time not instantly so there is more to it than you initially think.

I have some additional ideas that I intend to add to improve the display as the work progresses.

Wednesday 16 June 2010


I've been playing with code to add behaviour to the bots. At the moment this only relates to basic movement. They will either chase an enemy or return to their original task.

I am pleased with the results. It has been fun getting the bots to follow me about. They dart in then move away and jostle for position to get a good shot.

I also like the way that when they don't have a target they resort to the pathfinding to get back to their previous task.

I took some pleasure when I led them all to the far side of the map then ran away from them. They turned round at different times and eventually all worked their way back across the map to where they started.

If you have read my previous comments about pathfinding you'll know I was having performance problems with this. The basic pathfinding is unchanged. I did as I expected and have pre-calculated all the paths that I know before the game starts. These are saved with the map. All other paths needed are calculated during the game.

I use one hardware thread (on the Xbox 360) for any pathfinding requested and another hardware thread for all of the rest of the AI. I had to do this just in case working out any one path took too long. I did not want the reactions or behaviour to be held up. So far it's worked well.

Sunday 13 June 2010

Artificial Intelligence

The very short attached video shows the initial AI that I have added that makes the characters follow members of other teams.


The AI code used in that video is no longer used in the game.

Wednesday 9 June 2010


Over the weekend I was working on pathfinding. I'd already done some research and A* (A-star) pathfinding sounded to be exactly what I needed.

The code was fairly easy to design a basic solution and from the word go I had included a weighting system for squares I wanted bots to prefer. Such as near to cover.

Modifying the map file to include the weighting values took me longer to implement than the pathfinding.

The bad news. Even on the PC pathfinding took much longer than I had anticipated. At first I thought it wasn't working but when I left it 5 minutes it did calculate the paths. The problem was the first path I had given it was very long and it exceeded the 90,000 iterations I had set as my limit. I always add a limit when I use a while() to avoid endless loops!

I added some quick fix optimisation to my code. The first being to remove the closed list because it is unnecessary. A closed marker is more efficient.

At the moment I have also limited how many items it will check on the open list. The disadvantage is that on longer routes I may not get the best path, just any path!

I had also made some errors with the weighting levels I had set. These took some experimentation to sort out. Initially I had made the weights far too high and the paths got driven in to the wrong areas making them unnecessarily long!

At the moment on the PC, all my test paths now calculate quickly enough that you cannot notice unfortunately on the XBox 360 there are short pauses whenever a new path is needed! I'm already using a dedicated hardware thread on an otherwise unused core, just for the pathfinding!

That's where I'm at. I intend to pre-calculate as many paths as I can and I expect that will be sufficient but I am still researching and thinking, more than coding, on this bit.