Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Day 16: behavior Trees and I’m not dead yet (I’m getting better!)

I’m back! I’m bold! I’m--thinking that this is entirely too niche of a reference, so I’m moving on!

Oh boy, it has been a while. While I’ve utterly failed at devlogging every day, generally speaking I’ve been able to keep devving every day--Okay, with a couple of notable exceptions, but at one point my phone decided to kick the bucket and I had to go on a whole epic adventure to get a replacement. It was a thing. But I digress!

Most of the reason why I had avoided devlogging was out of shame, if I’m being honest. It turns out I’m way more out of practice programming than I realized, and I kept running into issues with my AI that I couldn’t code my way out of. The height (depth?) of the shame spiral was when I managed to get a stack overflow error in Unity, which was something that I had literally never managed to do before. I felt dumb, friends. 

The uptake of all of this is that I didn’t just give up. I tried two full iterations of my cop AI, first trying to run everything through a Switch statement, and then trying to iterate through different coroutines. I had varying degrees of success with each when it was just a matter of navigating through waypoints or chasing the player, but as soon as I tried to implement attacking behavior, it all just fell apart. After fighting with the scripts for a week I decided to change my approach and take a stab at creating a behavior tree.

I used some behavior tree assets in Unity in the past (most notably Rain by Rival Theory, if I want to really date myself here), and while I found the initial learning curve to be somewhat steep, I thought it might be worthwhile to attempt to bring them into DSAL. I can’t remember how I initially became aware of it, but I remembered a little BT system called Panda, and given that it had a free version, was well documented, and had multiple examples to study, I decided to give it a go. It was a decision I didn’t regret! I took a couple of days to get to know Panda, and then went about finally getting my cop AI where I wanted it to be. In the end, it was actually pretty simple to throw together. 

Panda was such a success that I was able to create the other patrolling AI within a few minutes of completing the Cop. So, DSAL now has a secondary fully functioning AI: Security!

(What do you mean they look alike?!)

Our Security friend here will actually be the first on the scene in the game--His team will be free roaming the office building from the moment our hero breaks in, though admittedly they don’t pose nearly as much of a threat as their police counterparts. Until Security spots the player, they’ll walk while they make their rounds throughout the building, and they’ll do it slowly. Once they see the player, they’ll start to run, but nobody in their division was on the track team--they run about half as quickly as the police, and their field of view is also reduced by half. In short, they’re really easy to avoid so long as their numbers don’t overwhelm the player.

Here’s the security guard and the police in action. You can see the cop is on the chase right away, while the guard feels like it’s out of his pay grade…

Eventually they both start beating on the grad. Rude.

So that’s it for now. Maybe it still doesn’t seem like much, but it really was a ton of work, and it represents getting past a major snag in production for me, so I’m rather pleased. Now that I’m comfortable with PandaBT, the remaining AI will be much faster to build. 

Completed today(over the last two weeks):

  • Learned PandaBT
  • Created Cop BT
  • Created Security BT
  • Created Security material swap
  • Created Security walk cycle
  • Put in soft hooks for game over scenario in game manager

Tomorrow TODO:

  • Office worker BT!