public override NodeStatus Tick(BehaviorBlackboard data) { Transform player = (Transform)data.Get("_BTD_Agent"); Transform target = ((Transform)data.Get(entry)); NavMeshAgent agent = player.GetComponent <NavMeshAgent>(); Vector3 playerPos = player.position; if (agent == null) { Debug.LogError("Behavor Tree Designer\nNo NavMeshAgent component found on node: " + this.name); return(NodeStatus.ERROR); } if (target == null) { return(NodeStatus.ERROR); } Vector3 targetPos = target.position; agent.stoppingDistance = stopDist; agent.destination = targetPos; if (Vector3.Distance(targetPos, playerPos) < stopDist) { return(NodeStatus.SUCCESS); } else if (agent.hasPath) { return(NodeStatus.RUNNING); } else { return(NodeStatus.FAILURE); } }
public override NodeStatus Tick(BehaviorBlackboard data) { int index = (int)data.Get("_BTD_WaypointIndex"); waypointParent = (Transform)data.Get("_BTD_Waypoint"); if (waypointParent == null) { return(NodeStatus.FAILURE); } Waypoints waypoints = waypointParent.GetComponent <Waypoints>(); if (!waypoints.circular && index == waypointParent.childCount - 1) { backwards = true; } if (!waypoints.circular && index == 0) { backwards = false; } if (backwards) { index--; } else { index++; } if (index >= waypointParent.childCount) { index = 0; } if (index < 0) { index = waypointParent.childCount - 1; } Transform target = waypointParent.GetChild(index); data.Add(entry, target); data.Add("_BTD_WaypointIndex", index); if (target == null) { return(NodeStatus.FAILURE); } return(NodeStatus.SUCCESS); }
public override NodeStatus Tick(BehaviorBlackboard data) { Transform agent = (Transform)data.Get("_BTD_Agent"); Transform child = agent.Find(childName); if (child != null) { ColliderHelper colHelper = child.GetComponent <ColliderHelper>(); if (colHelper != null) { if (colHelper.trigger != null) { data.Add(entry, colHelper.trigger); return(NodeStatus.SUCCESS); } else { return(NodeStatus.FAILURE); } } else { Debug.LogError("Behavor Tree Designer\nNo ColliderHelper script found on child: " + childName + " on object: " + agent.name); return(NodeStatus.ERROR); } } else { Debug.LogError("Behavor Tree Designer\nChild: " + childName + " not found on object: " + agent.name); return(NodeStatus.ERROR); } }
public override NodeStatus Tick(BehaviorBlackboard data) { GameObject[] objects = GameObject.FindGameObjectsWithTag(selectedTag); Transform agent; Transform closest; float minDist; if (objects.Length == 0) { return(NodeStatus.FAILURE); } agent = (Transform)data.Get("_BTD_Agent"); minDist = Vector3.Distance(agent.position, objects[0].transform.position); closest = objects[0].transform; for (int i = 1; i < objects.Length; i++) { float distance = Vector3.Distance(agent.position, objects[i].transform.position); if (distance < minDist) { minDist = distance; closest = objects[i].transform; } } data.Add(entry, closest); return(NodeStatus.SUCCESS); }
public override NodeStatus Tick(BehaviorBlackboard data) { if (this.Outputs[0].connections.Count == 0) { Debug.LogError("Behavor Tree Designer\nOutput node is not connected on node: " + this.name); return(NodeStatus.ERROR); } BaseBehaviorNode node = (BaseBehaviorNode)this.Outputs[0].connections[0].body; if (start) { data.Add(guid.ToString(), Time.time); } float time = (float)data.Get(guid.ToString()); if (time + waitTime > Time.time) { start = false; return(NodeStatus.RUNNING); } else { start = true; return(node.Tick(data)); } }
public override NodeStatus Tick(BehaviorBlackboard data) { if (this.Outputs[0].connections.Count == 0) { Debug.LogError("Behavor Tree Designer\nOutput node is not connected on node: " + this.name); return(NodeStatus.ERROR); } BaseBehaviorNode node = (BaseBehaviorNode)this.Outputs[0].connections[0].body; NodeStatus status = NodeStatus.SUCCESS; int rep = (int)data.Get(guid.ToString()); status = node.Tick(data); if (status == NodeStatus.RUNNING) { return(status); } rep += 1; if (rep < repNumber) { status = NodeStatus.RUNNING; data.Add(guid.ToString(), rep); } else { data.Add(guid.ToString(), 0); } return(status); }
public override NodeStatus Tick(BehaviorBlackboard data) { NodeStatus retVal = NodeStatus.FAILURE; switch (entType) { case EntryType.BOOL: if (boolEntry == (bool)data.Get(entry)) { retVal = NodeStatus.SUCCESS; } break; case EntryType.INTEGER: if (intEntry == (int)data.Get(entry)) { retVal = NodeStatus.SUCCESS; } break; case EntryType.FLOAT: if (floatEntry == (float)data.Get(entry)) { retVal = NodeStatus.SUCCESS; } break; case EntryType.CLASS: if (data.Get(entry) != null) { retVal = NodeStatus.SUCCESS; } break; default: retVal = NodeStatus.ERROR; break; } return(retVal); }
public override NodeStatus Tick(BehaviorBlackboard data) { object classObj; if (global) { classObj = data.GetGlobal(entry); } else { classObj = data.Get(entry); } if (classObj == null) { classObj = "null"; } Debug.Log("Behavor Tree Designer Logger\nEntry: " + classObj); return(NodeStatus.SUCCESS); }
public override NodeStatus Tick(BehaviorBlackboard data) { GameObject[] objects = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject)); Transform agent; Transform closest; float minDist; if (objects.Length == 0) { return(NodeStatus.FAILURE); } List <GameObject> layerList = new List <GameObject>(); for (int i = 0; i < objects.Length; i++) { if (objects[i].layer == selectedLayer) { layerList.Add(objects[i]); } } agent = (Transform)data.Get("Agent"); minDist = Vector3.Distance(agent.position, objects[0].transform.position); closest = objects[0].transform; for (int i = 1; i < objects.Length; i++) { float distance = Vector3.Distance(agent.position, objects[i].transform.position); if (distance < minDist) { minDist = distance; closest = objects[i].transform; } } data.Add(entry, closest); return(NodeStatus.SUCCESS); }
public override void Init(BehaviorBlackboard data) { base.Init(data); anim = ((Transform)data.Get("_BTD_Agent")).GetComponent <Animator>(); }