Reply To: JRPG Battle System

NodeCanvas Forums General Discussion JRPG Battle System Reply To: JRPG Battle System

#9029
Gavalakis
Keymaster

Hello,

BTs are very useful for decision making while FSMs are really good in decision making unless the FSM becomes very complex almost spagetti and even then, BTs excel in decision making. By decision making I mean that based on a nunmber of micro factors, a final decission (action) is chosen and executed.

FSMs are great when there are very dinsticive broad states of a behaviour/logic, like for example Attacking, Defending, Healing, Fleeing, Idling etc and the means of transitioning from one another is also quite broad. Do not try to represent a state as an action. ‘Attack’ is an action. ‘Attacking’ is a state. This is the simple rule of thumb I think when it comes to it.

So, in your case, you really want an NPC to decide what to do in his turn, based on a number of factors. Most probably there will be a single decided action in your case: Drink Healing Potion, Attack Cloud, Guard etc. So in my opinion a BT is far more flexible in this case, or in other words, you should use a BT for that 🙂

Now, there are some things to take notice for when you want to use a BT for turned based decision:
– You probably need to set the option on the BehaviourTreeOwner to ‘OnEnable:DoNothing’.
– You don’t want the BT to “Run Forever” in update, so you should uncheck the option “Run Forever” in the inspector of the BehaviourTreeOwner.
What this will do, is that when the BT is executed, is will be executed only once and then stop, which in practise can represent the “turn” for the NPC.

So in code, you can manualy start the BT by calling BehaviourTreeOwner.StartBehaviour when it’s the NPC turn to decide and do. You can even get a callback when that behaviour tree (turn in this case) is finished (so for example continue to the next NPC) by using an overload of the StartBehaviour method:
GraphOwner.StartBehaviour(System.Action callback);

Let me know if you need more help on the matter or code examples.

Cheers and thanks,
Gavalakis Vaggelis

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