NodeCanvas Forums › General Discussion › Looking for some Beginner help.
Hello people.
I’m new to this whole AI tree and logic thing so I’m jumping in head first into some scary waters here, but maybe i can get some friendly help. I have read through all the NodeCanvas Docs and watched all the online tutorials i could find but i’m just unsure what to do at times.
First example: I have set up a Character to patrol random points using the “nodecanvas” “Patrol node” but it is just to robotic how the character goes from one point to the next at a even and flat rhythm. What i want to do is add a wait time at each patrol point even randomize the wait time between 2 set values. What would be the way to do this, or would it be better to request this as a new node so its built in?
thanks
I have discovered the the Wait action that i could add to the patrol action node and just add a bunch of them but is there a eraser way to achieve a more random wait time?
I figured out away to do it but not sure how i really got there. If i let it run for a few minutes it fails to work properly and the character goes to the edge of the nav mesh and just stays there. It dose not patrol anymore. Is this a bug should i report it?
The red cubes are the patrol points, and the character is selected. see photo.
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!
Anax
Thanks for responding, I will have to look into those nodes you mentioned. I am a artist so I have no coding experience at all, that why I chose a visual scripting asset like nodeCanvas with hopes that I might be able to get some AI put together.
Thanks again.