89

The two are pretty different. The real indicator is in the names. Decision trees are just for making decisions. Behavior trees are for controlling behavior. Allow me to explain. A major difference in the two is the way they are traversed, likewise the way they're laid out and the node 'types' are different. Decision trees are evaluated from root to leaf, ...


16

See the image I provided in my previous answer: 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 ...


6

I found myself asking same question as you and I had great short conversation in comment section of this blog page where I was provided with another solution of the problem. First thing is to use concurrent node. Concurrent node is a special type of composite node. It consists of sequence of precondition checks followed by a single action node. It updates ...


5

I think your soldier may be decomposited into mind and body (and whatever else). Subsequently, body may be decomposited into legs and hands. Then, every part needs its own behaviour tree, and also public interface — for requests from higher or lower level parts. So, instead of micro-managing every single action, you just send instant-shot messages like "...


4

This is the way I see it, but really this is a decision you need to make based on what types of conditions/actions/behaviors you have. Actions: Running a function to process data. For example finding a path with A*. These happen in the background and aren't seen by the user. They usually happen in a single frame, but can stretch to a few frames if needed. ...


3

Laying in bed last night, I had something of an epiphany as to how I might go about this without introducing the complexity I was leaning towards in my question. It involves the use of the (poorly named, IMHO) "parallel" composite. Here's what I'm thinking: Hopefully that's still fairly readable. The important points are: the Sit down/Delay/Stand up ...


3

This can be achieved using decorators which can be read about here. I believe the syntax would be like this: (invert MyCondition). If that doesn't work you can always use a subtree as your guard. The syntax would then be like this: subtree name:"Invertedguard" invert MyCondition? ($Invertedguard)


3

Here is the solution I have settled on for now... My base Node class has an Interrupt method which, by default, does nothing Conditions are "first class" constructs, in that they are required to return bool (thus implying that they are fast to execute and never need more than one update) Node exposes a collection of conditions separately to its collection ...


2

That is not how you do do decisions in a behavior tree. If I understand correctly, your tree has this logic: while(true) { if (HP > 50%) { if (Visible enemy closer than 10m) { Aim Weapon Fire Weapon } else { Move } } else { Use Medkit } } ...


2

When you don't care about whether the whole subtree returns success of failure, then you could use the first version and wrap B in a Succeeder (a decorator which replaces the return value of its child with success): * Selector | +---* Sequence | | | +---* A | | | +---* Succeder | | | +---* B | +---* C That way C won't be executed no ...


2

Handling conditions Let's say I have a condition node which has to spend a lot of time calculating something to finally return a bool to the behavior tree. But in the following action, we need this information again. I worry about why you have to check the condition multiple times. Perhaps you could refactor your tree, so that you don't? These are the ...


1

Make the cleanup part of the "Flee" node. When it wants to make the actor flee, then it first needs to make sure that all the pre-conditions which are required for fleeing are fulfilled. Like stopping any ongoing animations.


1

In a Rimworld-like game you are dealing with NPCs who need to be able perform complex multi-step tasks (transport materials to workplace, craft item, transport crafted item to storage). And players expect their NPCs to perform those steps in a smart way and while considering all kinds of other priorities. Such complex multi-step tasks are far easier to ...


1

"In other words, I heard GOAP was better for projects where you have player made environment (or perhaps procedurally generated)." Please, who told you that "GOAP was better for ..."? I'd really like to know. What is at stake here is the following: planning need not be aware about the game. You can drop actions one morning, have the ...


1

I'll only speak of Planning. Unity provides a planner: you may wish to check that first instead of jumping into some GOAP Plugin (as amazing as they can be :-), or embarking into developping your own. If you wish to develop a planner, GOAP's principles are: NPCs have goals; have a procedure compute a goal for an NPC; this can be a method for each NPC class. ...


1

A solution that stays 'within' the language of Behaviour Trees, so to speak, would be to introduce a while node in your BT. Find a design that works for you, but one solution could be a composite node that always has exactly 2 children. It will run (and reset and rerun) the first, and, as long is it is not failing, it will also run the second. This will ...


1

If you are using C#, you can use interfaces. Implement an interface in the base method of all your nodes, then create a broadcaster class to invoke the method on the required node. If you are not using C#, you can use inheritance instead.


1

I fixed same issue by inventing "When" decorator. It has a condition and two child behaviors ("then" and "otherwise"). When "When" is executed, it checks condition and depending on its result, runs then/otherwise child. If condition result changes, running child is reset and child corresponding to other branch is started. If child finishes execution, whole "...


1

If you have the computational resources, it is best to evaluate the tree every frame. If CPU time becomes an issue, you may switch to event-driven BTs or update with lower frequency. Behavior Switching To properly handle switch to a different behavior, it is vital, that all your nodes enforce an init-update-done lifecycle. That is, prior to switching to a ...


1

I simply iterate, in one frame, until the whole tree finishes, or until an action/condition requests to suspend the traversal. Generally you would design your computation-heavy actions so that they only initiate a request to start their processing (instead of actually doing it there and then), which will then be handled by a different part of the game. You ...


1

Generally there would be no need to "swap" out trees. Build all your behaviors, add in your sequences and selectors to make your tree for your ai agent. Then for special case stuff you add decorators to stuff where needed. One big tree, per agent "type" so a soldier type would have a tree with patrol, attack etc etc and a miner would have a different tree....


Only top voted, non community-wiki answers of a minimum length are eligible