Thursday, August 8, 2019

ai - Behavior Trees :: Actions That Take Longer Than One Tick


From what I understand on Behavior Trees, each Behavior should be a short goal oriented Action that could be done in a few iterations.


So for example, below is an image of a Behavior Tree:


enter image description here


Now let us assume that the Drive To Enemy behavior takes more than a few iterations in the tree. So on each pass Drive To Enemy is called because it is now in the running state.


The problem is I want to call Evade Enemy if an Enemy is nearby. And considering that Drive To Enemy is always called I never get a chance to call Evade Enemy (Should probably be called Avoid Enemy).



  • Should I traverse the Tree EACH pass no matter what Action is currently running?


  • Am I going about this the right way?

  • What is the proper way of handling such a behavior?




Originally asked on Stackoverflow. Thought here would be a more appropriate place to ask this question.



Answer



See the image I provided in my previous answer:


enter image description here


If you imagine that node 1 is 'Evade Enemy' and node 2 is 'Chase Enemy', you'll see that even though in the second iteration (when everything is green except for '2' and 'B' is when the second iteration starts), 'Evade Enemy' still gets checked first. Only when 'Evade Enemy' fails, because there are no enemies near by, is 'Chase Enemy' activated again. When 'Chase Enemy' is visited again, it notices that it's in the 'running' state and skips directly to 'B'.


This means that every time the tree is checked, it will always traverse left to right. Even when a node is marked as running, the higher priority nodes are still checked first.



I'm not sure if you're meaning to process your nodes from right to left, but that's how you appear to have them arranged (i.e. under evade enemy, locate enemy is on the right of drive in opposite direction). If you need further explanation, you should ask in chat or in one of your existing questions on the topic.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...