top of page

Internship - Week 13 - Behavior tree

Hey there,

Last week we finished our cockroach behavior by adding in the JPS path finding, but before we can start working on other creatures like: dwarfs, mice, goblins, etc. We need to restructure/refactor the code. Right now, it is not suitable for multiple creatures to use it.

Lets list some of the main problems I'm having with the code that are keeping us from creating more creatures:

  • There is still a couple problems with the path finding. Imagine the situation where there is a creature in a maze, the distance between the creature and the target it wants to walk to is small, but the path to get there could be very long(image 1). Paths that are to long should be neglected. The path finding has more of these problems that all need to be fixed.

Image 1: short distance but long path, between creature and food.

  • A sizable chunk of the code is quite specific to the cockroach and should be decoupled, if we want to use it for other creatures.

  • I have changed the behavior tree before to make it better but it still has a lot of nodes/actions that are just checks and have nothing to do with behaviors. With this I mean nodes like: "ResetTimer", "DepleteStamina" and "IsFatiqued"(image 2). I only want nodes like: "Walk" and "Sleep" to remain in the behavior tree(image 3).

  • The creatures are lacking needs, if we had a need for every/most of the behaviors, it would be easier to see which behavior should be run. In the cockroach's case, he would have needs like: sleep, poop, dig and eat. Behaviors with a high need should be performed and behaviors with a low need, can be ignored.

  • The needs system should make it possible to get rid of timers and checks with random values. These checks were not creating interesting behavior for the creature. He seemed to do everything at steady intervals, which made his actions always look the same.

Lets have a look at what behavior tree looked like before and after these changes:

Image 2: old behavior tree.

image 3: new behavior tree.

As you can see, we went from a messy tree to a very simple tree that performs the same behaviors.

The creatures also became more interesting, since their behavior now depends on the needs they have. Each need has a value between 0 and 100, 0 meaning that it does not have to perform the related behavior and 100 meaning that it really needs to perform this behavior. But when it reaches 100 it usually is already to late and something will happen to the creature. It is possible to set rules for each behavior, which tell it when to run and when not to. For example, the creature should eat when his "Hunger"(need) has reached 60 but this is overruled when the "Sleep" need has reached 80. At this point, sleeping is more important than eating.


Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

Lars Temmink

Game Programmming Portfolio

bottom of page