Reply To: Expressing behaviours and state changes in BTs

NodeCanvas Forums General Discussion Expressing behaviours and state changes in BTs Reply To: Expressing behaviours and state changes in BTs

#9237
Gavalakis
Keymaster

Hey,

Personaly, I wouldn’t try to force myself creating a BT that works like an FSM since it’s a different logic, but I understand what you mean.
My choice would be something like the attached screenshot.
Every “state” (here an action for demo, but a subtree most certainly), is “layered” in priority, from highest to lowest. Thats the number one rule of thumb for BTs 🙂

So the Taking Damage is the most important one and it should happen no matter what.
Then the Attack, is higher priority than move, which means that if while I’m moving, I press the attack button, the attack will take place since it’s more important even if the ‘Move’ is not yet finished (eg animations).
The Move, well it’s just above the Idle and the Idle is the last resort, when nothing else is going on.

The way this is build layering priorities, it means that if I’m attacked and the ‘taking damage’ behaviour is going on, I am unable to move or attack myself or otherwise, since the Taking Damage is the higher priority.

Same of course goes for if I’m Attacking, I won’t be able to move until the Attack “State” is finished (eg finished animations etc)

The Dynamic Selector makes it possible to switch between those “States” at will as soon as the condition of the Accessor becomes true even while a lower priority “State” is not “Finished”. So we can think of the Accessors here kind like the transitions of an FSM, but possible to transit from lower to higher priorities only.

Personaly I would chose a more declarative/direct condition checking instead of an enum, unless there are a lot of things going on.

The condition for the move in this example is silly, but you get the point 🙂 You could check the velocity for example.
The condition for the Take Damage is a Check Event, which can be send to this agent from another agent or other means as an example.

So, again, the rule of thumb is to layer the behaviours/states in priority. There always have to be some 🙂

Im certain there are more ways to go about it, but this would be my personal preferance.

Join us on Discord: https://discord.gg/97q2Rjh