AI! IK! Ok…?
A few weeks ago while testing the game, I had to face the fact the AI (the artificial intelligence driving the enemies) was simply not good enough. It had become extremely bloated in terms of code complexity and yet was not quite delivering the quality I wanted.
So I decided to redo the entire game’s AI system from scratch, this time using a different behavior-tree technique.
It was a scary decision as during a few days the game wasn’t even playable; first I had to unplug all the actors’ “brains” and then I started again, slowly building up their new behaviors, piece by piece. I knew exactly what I wanted so I was able to get to the point rather quickly. But this time while I worked I hid away all the models, the animation, etc… and only used capsules.
Capsules are simple shapes that roughly represent the volume and orientation of the actors. Here’s an example with Tilo as you’ve probably never seen him before: he’s turned into a mix of a minion, a fire hydrant and a cucumber! 😀
(On the video you can see the capsule changing color depending on whether or not it’s in contact with the ground)
The result of this huge endeavor is in the span of 2 weeks I was able to redo and greatly improve the AI that had taken me more than a year to get into a flimsy “mostly-working” state. Except this time it is much more robust and I know exactly WHY it works the way it does.
So although the decision to redo the AI was a frightening one it ended up paying off BIG time:
- The AI asset I use is quite visual (it’s called “Node Canvas”), so I can see exactly what’s happening in real-time
- I was able to get rid of hundreds (if not more) of lines of codes, making the maintenance and expansion on the system much more manageable
- The capsule approach allowed me to focus on the behavior itself without animation clouding the potential issues
- The AI is now far richer than it’s ever been before and allows for really neat tricks
Here’s a bird’s eye view of what a behavior tree looks like. All the branches light up and change colors according to their state (as you can see in the inset picture).
I have also finally come around to implementing IKs for the actors. What this means is the character’s feet are now actually hugging the ground instead of remaining up in mid-air on a virtual flat-plane.
It wasn’t too difficult to implement thanks to a great asset I found called “Final IK”. Integrating the system into the game’s pipeline was painless and it yields very satisfying results! Here’s a quick test video:
(Don’t mind the red cube, it’s just a debug visual for the AI’s target position)
You’ll notice the Rat is really pushing on his legs as he climbs up the slope, contrasting a lot with Tilo who is a much lighter and nimbler character. Your speed (and the ability to sneak) is your main asset in the game; believe me, you don’t want to let these guys get their hands on you, especially without wearing any protections!!
Anyway, that concludes this update. I hope you liked it! Please don’t hesitate leaving your thoughts and questions below… 🙂