So I’ve got all the new zombies integrated into the game now, as well as all of the various different behaviors they can exhibit.
Zombies can now also get their heads crushed and destroyed, their arms ripped off, and their legs removed (forcing them to crawl after you). Depending on the occupation of the zombie, it may also carry a weapon or have extra armor. Zombies that wear helmets have to have their helmet knocked off before they’ll take any bodily damage.
There’s also a new three-tier wellness system I added (which replaces the old hunger system), which keeps track of your hunger, tiredness and blood levels. Beds that are found (or crafted) can now be slept on, and sleeping can also regain some HP depending on how tired you are when you fall asleep. Explosions and zombie attacks can also cause you to bleed out now, and if you do not find medical attention after the bleeding starts you’ll slowly lose HP and eventually die of blood loss.
Other various tweaks to the UI have been made, like popups showing important information and the amount of HP lost/gained after an injury/heal.
I’ve also optimized a lot of the background functions controlling the AI. The A* pathfinding algorithms now use about 40% less memory and are faster as well.
Here’s a youtube video showing most things mentioned above. Only thing to keep in mind is that the zombies in it are just generic neighborhood zombies, so you won’t see any of the ‘special’ ones like animals, clowns, swat members, etc…but don’t worry! They’re still in there!
Posted in AI, Zombox on January 1st, 2012 by Tyson Ibele
So, over the last two weeks I’ve been updating the zombie AI.
The old AI system had many problems, was hard to update, and lacked many important features. So I started from scratch and implemented a behavior hierarchy, similar to the one described in this book.
Here are some key features of the new system:
zombie AI is now sight/sound based. Zombies will tend to wander around aimlessly, until they see/hear something that catches their attention. Things like the sound of the player hitting an object with a blunt weapon, or firing a gun will attract zombies, but they won’t automatically know what caused the sound. This means that zombies can be distracted with sounds while the player heads in the opposite direction. It also means that it’s now possible to sneak up on zombies from behind.
zombies now flock more realistically. No longer will they randomly intersect walls, or the player, or each other. When attacking, they’ll also try to surround their target.
zombies will try to break down the doors of buildings, if they see a human/hear a noise inside.
I’ve also improved several other aspects of gameplay. Items that require ammo now display their ammo counter inside their icon, when assigned to any of the active item slots. Also, zombies and props can no longer be hit through walls or other solid surfaces.
Here are some screens showing the debug info I use to help me visualize the new AI system. White lines show new A* paths that are calculated. Green lines point to the next node on a zombie’s path when the zombies is following a sound. Magenta/Cyan lines point to a zombie’s active target (cyan = close, magenta = far). Red lines show the next node on a zombie’s path when the zombie is chasing a target (although zombies are allowed to veer off their path when the target is directly in range). Yellow lines point to a new sound that a zombie has heard.
This week’s work on Zombox was sporadic and mostly behind-the-scenes.
The biggest changes are the following:
-weapons can now damage the environment. Got a hammer? Smash down a wall. Got an axe? Chop down a street light.
-zombie AI and flocking algorithms have been improved. Zombies no longer intersect one another while crowding around the player
-zombie pathfinding has been improved. The A* algorithm now runs in a co-routine so it can process a path over multiple frames, lessening the load on the CPU and allowing for longer paths to be calculated
-objects and enemies can be pushed in the water now. They’ll splash and drown but so can the player so you shouldn’t go too close to the edge!
This week I had some time to update the weapons and crowd dynamics of Zombox.
There are now different types of zombies…some are smaller/weaker/faster, others are larger/stronger/slower. Some are wearing helmets or protective gear and have more health, others carry simple melee weapons and can deal more damage.
Also, the zombie flocking algorithms have been updated. Zombies now flock around the main player more dynamically, and can be pushed out of the way as you move forward. The zombie physics system has been updated so that certain weapons and attacks can knock zombies back causing them to roll around and knock into nearby scenery.
All weapons have been updated in various ways. Melee weapons will drip drip more blood after hitting a zombie, push the zombies back more and their collision systems are more precise. Firearms do less damage from greater distances, can fling zombies backwards, and sharp projectiles that shoot out of certain firearms (like crossbows and nailguns) will stick into zombies and other hard surfaces. Also, the special taser weapon will electrify zombies, dealing secondary damage over time. Critical hits will cause blue sparks to emanate outwards from the affected zombies, giving subtle visual feedback on the level of damage dealt.
I haven’t posted any new developments for Zombox in a couple of weeks because I’ve mainly been doing code re-writes, optimizations and other things to get the game running faster on iOS.
One of the main hiccups in development has been the zombie AI. Until this week, zombies “saw” their environment with raycasts. While I was pooling raycasts and not doing 1 per frame per zombie, raycast performance with 30-40 zombies and many colliders on the iOS was slow. Also, while zombies don’t require an overly complex AI system, the previous I-won’t-chase-it-unless-I-see-it method left them unnecessarily dumb. Not to mention, the AI system couldn’t really be scaled up to include NPCs that need to be able to find targets.
So, I implemented an A* pathfinding system for all AI instead. The main hurdles I encountered while working on this system were: