Wednesday, May 6, 2015

Big Game Project, Week 4

Hi,

I'm a bit late with this post but this is for week 4 of the project. So this week (previous week) I was put on handling AI so I have put the menu and HUD stuff on hold for now. So lets dive into behavior trees!




For AI we will use Unreals built in behavior tree. The behavior tree in Unreal is a very big plus for the Unreal engine because it makes this so much more easy because normally when you create behavior trees in code you need to visualise it or draw it down on paper to understand it and here Unreal allows you to build it visually right in the engine. You can also see where in the tree the AI/NPC is at run time by opening the window next to your game. its amazingly good!

For those of you who want to know more about behavior trees in general here is a good link:

http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php

The tree starts from the top with the root node and works it way down and it starts going to the left branches and works itself down all the way and moves right when it can't move further down. It's kind of like a finite state machine but in a three structure where it chooses different paths in the tree depending on if different conditions are met or not.

My tree is still work in progress and is still very simple. It works something like this:
Do I see an enemy? if yes then attack, if no just wander around. That's basically what the tree does now.

Here is a screenshot of the wander part of my tree.































It first checks if I have a Target (enemy), if not then it will step down to the left and check if I have a TargetLocation to walk to, If not it finds a random spot in a certain radius and sets that as the next TargetLocation. After that it goes to the next task and sets the walking speed to 150. When that is done it returns true all the way up the tree.

Next time this three is run it won't go down to the left because it has a TargetLocation set so it will move done right and move to the TargetLocation. When the TargetLocation is reached it will move back to its starting position, it's HomeLocation. Fairly simple and it works quite well. I didn't choose Unreals built in walk to tasks, I made my own custom walk to tasks that also checks to see if a enemy is spotted while walking and if it is it return false up the tree to trigger the other parts of the tree related to attacks.

One thing that is fairly easy to forget when starting out with behavior trees is that it can be very easy to forget to add both success and fail on tasks when they are done (as seen below). I forgot to put a fail on a task that needed it and the tree got stuck there every time it ran and I couldn't for my life figure out why. Depending on how you build the tree this might be very important and I would say add fail on tasks rather then not adding fail even if it might seem pointless at the time.


In a few days I will write my next post and continue on behavior trees.