NodeCanvas Forums › General Discussion › Looking for some Beginner help. › Reply To: Looking for some Beginner help.
Hey buddy welcome. Judging by your posts it seems that you know what you are looking for, it’s just that you need more practice. Bare in mind that the subjects of Behavior Trees and State Machines areĀ hard to grasp even for a large portion of software developers. I know how you feel because thats how I felt when I started and I still need a lot of practice myself.
I suggest you find more BT examples on the web and study them. NodeCanvas is just an interpretation of BT theory and it is not necessarily in the scope of the product to explain how BTs work. A good place to start, if you haven’t done so already is: https://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php
For your example I would also try to use an Iterate Decorator. As for the random wait time remember that you can build your own Decorators. Here is how I have modified a Timeout Decorator to act as a Wait:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEngine; namespace NodeCanvas.BehaviourTrees { [Category("Decorators")] [Description("Waits for a certain amount of time before executing the next node.")] [Icon("Timeout")] public class Wait : BTDecorator { public BBParameter period = 1; private float timer; protected override Status OnExecute(Component agent, IBlackboard blackboard) { if (decoratedConnection == null) { return Status.Optional; } timer += Time.deltaTime; if (timer >= period.value) { return decoratedConnection.Execute(agent, blackboard); } return Status.Running; } protected override void OnReset() { timer = 0; } ///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override void OnNodeGUI() { GUILayout.Space(25); var pRect = new Rect(5, GUILayoutUtility.GetLastRect().y, rect.width - 10, 20); var t = (timer / period.value); UnityEditor.EditorGUI.ProgressBar(pRect, t, timer > 0 ? string.Format("Timeouting ({0})", timer.ToString("0.0")) : "Ready"); } #endif ///---------------------------------------------------------------------------------------------- } } |
If you want a random timer then you can simply assign a random float using UnityEngine.Random.Range(float min, float max);
Best of luck and good practicing!