Argh, just under 2 weeks to go until Rezzed!
Most of this week I spent completely rewriting the AI system for the monsters, replacing the test spaghetti code with a proper behaviour tree implementation that I had lying around from last year's prototype. I couldn't afford the Behave plugin, so I used my own code instead.
Most behaviour tree libraries for Unity include some sort of graphical node editor. However, I figured that since it's actually a tree and not a graph, it would be fine to just use the scene hierarchy instead.
You can see it's still pretty easy to create new behaviour nodes and edit their parameters in the Inspector View. The beauty of behaviour trees is reusability of nodes, and also it is a lot easier to see how each behaviour is dependent on others. To share data between nodes and iterations, I'm using a simple blackboard system. Pretty much just a key value store, with one per monster. Some behaviours allow monsters to look up other blackboards as well. With this system I should be able to start fleshing out some pretty complex monsters pretty quickly. The above screen shows a really small part of the Skeleton behaviour, the bit that makes it chase the player around the dungeon.
Most of TinyKeep is based on reactive AI - so for chasing, monsters can take advantage of player breadcrumbs instead of pathfinding. Steering behaviour is also used to avoid walls, strafing around corners and other types of manouveur. However, for other behaviours such as patrolling and fleeing, I really needed some kind of rudimentary pathfinding system. Unity does come with a really nice navigational mesh feature, unfortunately this is unavailable to me as I am using procedurally generated content. Unless I'm seriously mistaken, Unity NavMeshes must be baked at editor time. So I spent most of today adding dynamic waypoints to the generated dungeon for use with A*.
Calls to the A* pathfinding system occur very rarely, normally only when the monster has nothing to chase or follow. An average mob probably executes pathfinding once every 5 seconds or so. Used in conjunction with the breadcrumbs, steering behaviours and the behaviour tree - it's turning out to be quite a nice little system to play with.
We shall see next week what happens with the mobs now!