Internship - Week 14 - Dwarf
Hey there,
It is time to move on from the cockroach and create a dwarf creature. as we all know, dwarfs love to dig and our dwarf is not going to be an exception. this week, we will be creating the design of dwarf and implementing some of his digging capabilities.
Gif 1: Dwarf digging diagonally towards food.
He will also have all the behaviors of the cockroach, he will be able to wander, sleep, eat, find food and Poop. This will require us to make some small changes to the creature code. right now all the behavior code that is called by the behave library is located in the CockroachBehavior script. We should implement a base class which holds all the behaviors that are shared between the cockroach the dwarf and other creatures in the future. This means that both the cockroach and the dwarf will need to inherit from a ParentBehavior script.
Next we should figure out all the extra behaviors the dwarf is going to have. I was thinking off adding these extra behaviors:
He can create a base in which he sleep, eats and stores his gold.
He can find a location to start a mine.
He can dig in the mine to find gold which he brings back to the base.
His path finding will be slightly different. When a path to food source is way too long, he will dig a path there instead.
This should add some pretty interesting behavior to the dwarf.
With the design a bit more defined, it is now time to create the behavior tree for the dwarf. Luckily we made some changes to the layout of our trees last week. If we hadn't, this new tree would be very difficult to create and manage. With the changes this should be verily easy and take little time.
After some tinkering, this is the final tree I came up with: (for now!)
Image 1: Dwarf's behavior tree.
With that finished, it is time to create the ParentBehavior tree and get everything ready and working for the multiple creature setup. This was a pretty tedious and boring process where I mostly shifted code around and added little changes everywhere.
Lets get too the more interesting part!
Changing the path finding so the dwarf can dig through walls when necessary. Instead of looping through the list of targets until we find a target that has a small enough path(this is what the cockroach does), we only look at the closest target and detect if the path is short enough to walk or if we should dig our way towards the target.
After this, we only have to add the wall tile to the dwarf's list of walkable tiles and create the
........ DigToTarget ....... script, which will replace a wall tile with a path tile.
Gif 2: Dwarf walking towards food.
Gif 3: Dwarf digging towards food.
Testing showed me that there are still some problems with this implementation. For example, the dwarf will walk diagonally when it is not suppose to(the diagonal tile is blocked by a neighboring wall tile). We will deal with these problems next week.