Saturday 14 January 2012

Realistic pathfinding

Well I've finally managed to get the Zommers to take a more realistic path when trying to get to the player. They look at where the player is, and if there is an object in the way, calculate the most efficient way around it. This is still pretty basic stuff, but it's way more advanced than my last attempt, and you can tell that just by looking at the entities in action.

At the moment, they all try to head directly for the player. I want to work on some routines where they wander around aimlessly (as Zombies tend to do) but then change behaviour if the player comes with a certain distance of them, or attracts them in some other way...

Here's a (short, low quality) video of the routine so far...


Since making that video, I have added the ability to delete a random Zommer (by pressing the 'x' key) and also spawn a new Zommer (by pressing the 'c' key). That might sound pretty straightforward, and the delete function is - it only has to check if a Zombie exists, then deletes it. But the spawn function is a bit more involved. It has to find the first available "entity slot" that isn't in use, and assign all the right variables according to its findings. There are only so many slots available - I have to draw the line somewhere!

For the demo above, the controlling variable is

#constant NUM_ZOMBIES 8

It's pretty obvious what that line does, but if I want to have 100 Zommers, I only need to change that number from 8 to 100 and the rest of the code adjusts accordingly. 

I'm not sure what to aim for next. I have a couple of things that need doing which won't make the project look any different, but involve some big(ish) changes "under the hood". I have a few days off coming up soon, so I might try and work on different Zommer behaviours. Or maybe health. I want each Zommer to have its own individual health level, and that means adding more attributes to the entity definition.

Onwards and upwards :)