Artificial Intelligence comes to Z-Day
by Andy Rollins · 04/12/2009 (4:14 am) · 23 comments

As I mentioned on the last blog, we've wrapped up our alpha v0.25, have fixed up the major bugs found and it's full steam onto the Artificial Intelligence, although there will be an element of PvP in the game it's the Zombies that will pose the major threat so it's a key part of the design to get them moving, thinking and attacking with enough challenge to keep players interested.
So where does that process begin?
For us that's been with a lot of reading through books, blogs, forums and articles to gain ideas and see if there are some existing product we could use, we did finding some truly stunning A.I. middleware unfortunately though all of it had one problem... the price tag!There are some great A.I. and pathfinding resources on the site here Dan Kellers Flexible A* and Gavin Bunneys Immersive AI engine to name just a couple but they're all based on waypoint grids and we wanted a NavMesh based approach for pathfinding which leaves us one option... code our own solution (I know, I know, it's horrible actually having to code something ourselves!!)
Onwards then to;
Phase 1 - Pathfinding
The first phase has to be pathfinding, if the zombies can't move around the city well then the rest of the AI may as well be forgotten any of the behavioural elements we want to add all require some type of movement so seems as good a place as any.I could spend a long time talking about the pro's and con's of waypoint grids vs NavMeshs but for those interested I think Paul Tozours blog sums up things much better than I could write. So we're going for a Nav Mesh based approach - that is a set of connected convex polygons (we're choosing triangles for simplicity to begin with) but any convex poly would work and N-sided polys would be great we'll save that for a later date though.
The NavMesh will be built up from a few classes starting at the bottom these will be:Points - These are simply vertices that are used to construct the Nodes.
Nodes - A set of three points that form a triangle and represents an area that an AIplayer can walk around freely within without hitting anything else.
Grids - These are purely for helping the editing of the Mesh, rather than trying to work on the entire world at once we tie Nodes to a grid and will then turn on and off editing of nodes within that grid. We've chosen to make grids tied to objects in the world i.e. Interiors or Static objects and take that objects bounding box as the boundary for placing nodes in that grid area - its both a nice logic way but it'll mean if we move or rotate the world object we can then move/rotate all objects in the grid to match it rather than having to redraw the entire mesh.
Zones - A zone is a collection of Nodes just like a grid, except these are used for actual gameplay and are more strategically placed and serve a number of purposes:1. Hierarchical A*Star - with a large map it would be faster to first calculate a route through the zones and then at a more detailed level when you're in that specific zone (think of it as LOD system for Pathfinding)
2. Precalculated paths - as a Zone will have predefined entrances and exits when you're just needing to find a path through that zone these can be precalculated and stored in memory then used many times.
3. Learning - Common to most FPS games is that some buildings or areas of maps see a lot more of the player traffic, human players soon learn those areas and that's something else zones give us, the ability for the A.I. characters to learn which zones are used most then we can use that data to seek in those areas more often or direct more of the AI characters to those areas.
4. Strategic Attacks - We've all seen the movies with some form of monster trying to attack and break into the house from every available entrance... marking a zone out for a building will let us be more strategic with our attacks breaking into the house from several directions.
etc, etc...
The Team
Obviously that's quite a lot to deliver and write so it's going to require more work than I alone could reasonably deliver in a shortish time frame so let me introduce you to the team:Chris Gosling - All round star of Z-Day, Chris is one of those really annoying people that is great at both artistic (modelling & texturing) work and coding...he's been leading up the design and pathfinding elements of what we're working on, it's rumoured that Chris works a standard 32hr day and as an Australian when he's not teasing us Brits about the weather he's off to the beach.
Daniel Delp - A recent addition to the Z-Day team Dan has jumped straight into things porting over Z-Day to run on a Mac (mostly complete unfortunately we can't get DXTC textures working on a mac just yet), its great to have Dan as part of the team some of you may have seen his blogs on some A.I. work he'd being doing on TGE and we're pleased to say that he's ported over the automatic Mesh Generation to TGEA. When Dan's not coding on Z-Day he's off out Snowboarding on the powered white stuff.
Myself - Apart from the fact that I get to write these blogs and take all the glory, I've been working on getting an Editor for the NavMesh working within TGEA and when I'm not focused on that then I'm off Mountain Biking or topping up my alcohol levels.
So what have a Beach Bum, a Snowboarder and an Alcoholic achieved so far since my last blog a month ago, well enough of the words here's a video to watch of an early prototype of the editor
(excuse the numbers of "errms" and "and again" for some reason I couldn't stop saying them!!)
We'd be really interested to hear from anyone that has any thoughts, comments or suggestions or even if you'd like contribute and work with us so please get in touch.
Hopefully we'll have more to share with everyone soon until then thanks for reading.
About the author
#2
You don't really need any LOS checking at all.
04/12/2009 (6:45 am)
@Steve - thanks for the comment, yeah similar each node (triangle) works like your normal waypoint would moving from one to the next because we know triangles are convex we know we can walk anywhere within that triangle without bumping into anything.You don't really need any LOS checking at all.
#3
aka: How do they a single point in space on the last triangle?
eg: get to last triangle and then Aimat(%goal) and then distance check until they are at the exact location?
EDIT: Actually, yes, that would work wouldn't it? In Torque's case it's just a standard setmovedestination from then on. (aimat and move)
The ai-blog.net article you linked to is interesting. Especially the video of bad pathfinding in 3A games. Oh how I laughed!
04/12/2009 (6:58 am)
Mild confusion. How does the AI find the exact location of the goal once they have moved down the route and are standing on the same triangle?aka: How do they a single point in space on the last triangle?
eg: get to last triangle and then Aimat(%goal) and then distance check until they are at the exact location?
EDIT: Actually, yes, that would work wouldn't it? In Torque's case it's just a standard setmovedestination from then on. (aimat and move)
The ai-blog.net article you linked to is interesting. Especially the video of bad pathfinding in 3A games. Oh how I laughed!
#4
04/12/2009 (8:02 am)
wow thats really nice, i didnt realize you had such a thick accent lol, but this is definitly a tool id invest in once it gets cleaned up.
#5
04/12/2009 (8:05 am)
@Edward - if you think that's a thick accent you'd have no chance of understanding a word I say!
#6
I think everyone I've shown that blog article too has had a good giggle at how easily some of these characters get stuck in AAA games - even a million dollar budget doesn't guarentee you good pathfinding.
04/12/2009 (8:17 am)
Yes Steve that's the intention to just use setMoveDestination() once you reach the final triangle. More than likely we'll be doing LOS tests and some path smoothing prior to that though to help give a more direct and natural path - we haven't fully tied that down yet though.I think everyone I've shown that blog article too has had a good giggle at how easily some of these characters get stuck in AAA games - even a million dollar budget doesn't guarentee you good pathfinding.
#7
04/12/2009 (8:19 am)
Lol thanks Edward we're hoping to get it nicely polished in the next month or two. As for accents as Steve mentions mine is quite plain compared with some parts of the UK even Yorkshire isn't too bad its the Glaswegian I really struggle with.
#8
I would love to see some AI using the navmesh to chase you! Do you have plans to be able to extend the mesh outside the bounds of an object, like at the entryways? Its seems like mobs would still get stuck outside if they hit a wall. I really like how it makes the mesh only around objects the AI might get stuck on, rather than whole areas of the zone.
Also with the auto generated meshes... it would be cool if you could go back and delete parts once you generate one.
Keep up the good work, this seems like it could be an add-on that lots of devs would be interested in, were you to release it.
04/12/2009 (8:41 am)
Great vid.I would love to see some AI using the navmesh to chase you! Do you have plans to be able to extend the mesh outside the bounds of an object, like at the entryways? Its seems like mobs would still get stuck outside if they hit a wall. I really like how it makes the mesh only around objects the AI might get stuck on, rather than whole areas of the zone.
Also with the auto generated meshes... it would be cool if you could go back and delete parts once you generate one.
Keep up the good work, this seems like it could be an add-on that lots of devs would be interested in, were you to release it.
#9
I really like the idea of your hierarchical A* pathfinding - you know you have to navigate through these three buildings, but it's not necessary to navigate the detailed path *just* yet.
04/12/2009 (12:57 pm)
That's really, really cool, and a great explanation in your video. I've just decided to implement navmeshes for my own pathfinding ;). I guess you guys are using DIFs, but would it be easy to, for example, create navmeshes within a modeling app when exporting polysoup DTS shapes? I'm thinking that would be a better solution for at least my own game.I really like the idea of your hierarchical A* pathfinding - you know you have to navigate through these three buildings, but it's not necessary to navigate the detailed path *just* yet.
#10
04/12/2009 (2:15 pm)
that is some awesome work Andy, Like Edward i too would invest in such a tool. Looking forward to seeing more on this. Good job so far.
#11
I didn't show it on the video but yes you can already delete items from the mesh once you've autogenerated it.
@Daniel - The manual solution works on both DIFs, DTSs, terrain almost any object in game we have only got the auto-generation working for Interiors (DIFs) right now but plan on expanding that to DTS and terrains. It should be a solution to fit most peoples needs
@Roland - Thanks for the compliment, we'll sure be sharing more as things develop.
04/12/2009 (2:47 pm)
@Jondo - Yes the navmesh can be linked outside of the bounding boxes, we've no added it yet but there will be a special grid for the terrain area that will be a *catch all* bucket plus you will be able to select more than one grid at once to allow them to be joined up.I didn't show it on the video but yes you can already delete items from the mesh once you've autogenerated it.
@Daniel - The manual solution works on both DIFs, DTSs, terrain almost any object in game we have only got the auto-generation working for Interiors (DIFs) right now but plan on expanding that to DTS and terrains. It should be a solution to fit most peoples needs
@Roland - Thanks for the compliment, we'll sure be sharing more as things develop.
#12
I think English accents are great. :-)
04/12/2009 (4:30 pm)
Wow it looks brilliant. Really nice. Looking forward to seeing how this moves forward.I think English accents are great. :-)
#13
04/13/2009 (6:30 am)
Great work, I had to come to the same conclusion myself on creating our own ai engine. We have some of the same books too. Any favorites that you can recommend to me?
#14
@Glenn - A lot of the books the Gems and AI Wisdeom ones especially are mostly theory based, so it depends on whether that's your cup of tea there are some very well written articles in them but it's geared more to adding to knowledge and concepts rather than learning to code A.I. On the flip side the Programming Game A.I. by Example is an excellent book and includes a lot of practical examples.
04/13/2009 (7:09 am)
@Edward - thanks, I get quite a few comments about my accent.@Glenn - A lot of the books the Gems and AI Wisdeom ones especially are mostly theory based, so it depends on whether that's your cup of tea there are some very well written articles in them but it's geared more to adding to knowledge and concepts rather than learning to code A.I. On the flip side the Programming Game A.I. by Example is an excellent book and includes a lot of practical examples.
#15
04/13/2009 (11:28 am)
Is this something that you will be putting up for sale? I sure could use something like this immediately.
#16
We are intending to see once it's finished whether we can sell it as a pack for others to use.
04/13/2009 (12:05 pm)
@Robert - It's a little early to start talking about selling it, right now we've only just got the early editor up and running so there's still a lot to do to code all the pathfinding elements.We are intending to see once it's finished whether we can sell it as a pack for others to use.
#17
Thanks.
04/13/2009 (12:08 pm)
Please keep us updated. This is on the lines of what multi million dollar companies are using for their games and I will be the first one in line waiting for this.Thanks.
#18
If you really need pathfinding asap there are resources here on-site, all old waypoint styles.
04/13/2009 (12:57 pm)
@Robert - a lot of "multi million dollar companies" aren't using anything this advanced!If you really need pathfinding asap there are resources here on-site, all old waypoint styles.
#19
04/13/2009 (1:30 pm)
Very cool!! When we were working on the never-released Torque AI Pack we had all the auto-node-generation stuff working etc. but never had any way to edit the generated navmeshes or place them manually with an editor - awesome work and looking forward to see more! :)
#20
04/13/2009 (4:11 pm)
@Stefan - When we were hunting around for AI info I came across the blogs on the AI Pack, it sure looked promising stuff it's a shame you guys didn't get as far as releasing it as I'm sure we'll go through much of the same headaches you did with trying to auto-generate a mesh. 
Associate Steve Acaster
[YorkshireRifles.com]
I'm more used to the idea of waypoint based navigation, so one big question on how this works:
Does the AI find the target/goal by moving to the triangle it's on and then use LOS to close on the target/goal?