• Register

TinyKeep is an upcoming action roguelike game with procedurally generated dungeons, emergent monsters, deadly traps and mysterious secrets.

Post news Report RSS Rewriting the AI system

If you haven't tried to implement behaviour trees into your game, stop what you're doing right now.

Posted by on

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!

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Windows, Mac, Linux
Phigames UK
Send Message
Release date
Game watch
Post news
Related Games
TinyKeep Roguelike
Related Engines
Unity Commercial