public static CandiceBehaviorStates RotateTo(CandiceBehaviorNode rootNode) { CandiceBehaviorStates state = CandiceBehaviorStates.SUCCESS; try { float desiredAngle = 180; int direction = 1; float angle = Vector3.Angle((rootNode.aiController.MainTarget.transform.position - rootNode.aiController.transform.position), rootNode.aiController.transform.right); if (angle > 90) { angle = 360 - angle; } if (angle > desiredAngle) { direction = -1; } float rotation = (direction * rootNode.aiController.RotationSpeed) * Time.deltaTime; rootNode.aiController.transform.Rotate(0, rotation, 0); } catch (Exception e) { state = CandiceBehaviorStates.FAILURE; Debug.LogError("CandiceDefaultBehaviors.RotateTo: " + e.Message); } return(state); }
public static CandiceBehaviorStates MoveForwardWithSlopeAlignment(CandiceBehaviorNode rootNode) { CandiceAIController agent = rootNode.aiController; agent.IsMoving = true; /*if (rootNode.aiController.hasAnimations) * { * if (rootNode.aiController.animationType == AnimationType.CodeBased) * { * if (!agent.currentAnimation.Equals(agent.moveAnimationName)) * { * agent.currentAnimation = agent.moveAnimationName; * agent.Animator.Play(agent.moveAnimationName); * } * } * else * agent.Animator.SetBool(agent.moveTransitionParameter, true); * }*/ //rootNode.aiController.Animator.SetFloat("characterSpeed", rootNode.aiController.movementSpeed); CandiceBehaviorStates state = CandiceBehaviorStates.SUCCESS; try { agent.movementModule.MoveForwardWithSlopeAlignment(agent.transform, agent); } catch (Exception e) { state = CandiceBehaviorStates.FAILURE; Debug.LogError("DefaultBehaviors.MoveTo: " + e.Message); } return(state); }
public static CandiceBehaviorStates Wander(CandiceBehaviorNode rootNode) { CandiceAIController agent = rootNode.aiController; agent.Wander(); return(CandiceBehaviorStates.SUCCESS); }
public CandiceBehaviorNode CreateBehaviorTree(CandiceAIController agent) { Initialise(); rootNode = null; CandiceBehaviorNodeS _rootNode = null; nodes = behaviorTree.GetNodes(); _rootNode = nodes[0]; Debug.LogError("Agent: " + agent.AgentID); switch (_rootNode.type) { case CandiceAIManager.NODE_TYPE_SELECTOR: rootNode = new CandiceBehaviorSelector(); rootNode.id = _rootNode.id; rootNode.Initialise(agent.transform, agent); (rootNode as CandiceBehaviorSelector).SetNodes(GetChildren(behaviorTree, _rootNode)); break; case CandiceAIManager.NODE_TYPE_SEQUENCE: rootNode = new CandiceBehaviorSequence(); rootNode.id = _rootNode.id; rootNode.Initialise(agent.transform, agent); (rootNode as CandiceBehaviorSequence).SetNodes(GetChildren(behaviorTree, _rootNode)); break; } return(rootNode); }
public static CandiceBehaviorStates AttackRange(CandiceBehaviorNode rootNode) { CandiceAIController agent = rootNode.aiController; agent.AttackRanged(); return(CandiceBehaviorStates.SUCCESS); }
public static CandiceBehaviorStates WithinAttackRange(CandiceBehaviorNode rootNode) { CandiceAIController agent = rootNode.aiController; if (agent.WithinAttackRange()) { return(CandiceBehaviorStates.SUCCESS); } else { return(CandiceBehaviorStates.FAILURE); } }
public static CandiceBehaviorStates AllyDetected(CandiceBehaviorNode rootNode) { CandiceAIController agent = rootNode.aiController; if (agent.AllyDetected) { return(CandiceBehaviorStates.SUCCESS); } else { return(CandiceBehaviorStates.FAILURE); } }
public static CandiceBehaviorStates ScanForObjects(CandiceBehaviorNode rootNode) { try { CandiceAIController agent = rootNode.aiController; agent.ScanForObjects(); return(CandiceBehaviorStates.SUCCESS); } catch (Exception ex) { Debug.LogError(ex.Message); return(CandiceBehaviorStates.FAILURE); } }
public static CandiceBehaviorStates LookAt(CandiceBehaviorNode rootNode) { try { CandiceAIController agent = rootNode.aiController; agent.movementModule.LookAt(agent.transform, agent); return(CandiceBehaviorStates.SUCCESS); } catch (Exception ex) { Debug.LogError(ex.Message); return(CandiceBehaviorStates.FAILURE); } }
public static CandiceBehaviorStates CandicePathfind(CandiceBehaviorNode rootNode) { try { CandiceAIController agent = rootNode.aiController; if (agent.CandicePathfind()) { return(CandiceBehaviorStates.SUCCESS); } else { return(CandiceBehaviorStates.FAILURE); } } catch (Exception ex) { Debug.LogError(ex.Message); return(CandiceBehaviorStates.FAILURE); } }
List <CandiceBehaviorNode> GetChildren(CandiceBehaviorTreeS bt, CandiceBehaviorNodeS node) { List <CandiceBehaviorNode> children = new List <CandiceBehaviorNode>(); CandiceBehaviorNodeS _node = null; if (node.childrenIDs.Count < 1) { return(children); } foreach (int id in node.childrenIDs) { CandiceBehaviorNode newNode = null; Debug.LogError("ID: " + id); if (GetNodeWithID(id, bt.GetNodes()) != null) { _node = GetNodeWithID(id, nodes); switch (_node.type) { case CandiceAIManager.NODE_TYPE_SELECTOR: newNode = new CandiceBehaviorSelector(); (newNode as CandiceBehaviorSelector).SetNodes(GetChildren(bt, _node)); break; case CandiceAIManager.NODE_TYPE_SEQUENCE: newNode = new CandiceBehaviorSequence(); (newNode as CandiceBehaviorSequence).SetNodes(GetChildren(bt, _node)); break; case CandiceAIManager.NODE_TYPE_ACTION: CandiceBehaviorAction action = new CandiceBehaviorAction((CandiceBehaviorAction.ActionNodeDelegate)lstFunctions[_node.function].CreateDelegate(typeof(CandiceBehaviorAction.ActionNodeDelegate)), rootNode); newNode = action; break; } children.Add(newNode); } } return(children); }
public static CandiceBehaviorStates SetAttackTarget(CandiceBehaviorNode rootNode) { CandiceBehaviorStates state = CandiceBehaviorStates.FAILURE; CandiceAIController agent = rootNode.aiController; try { if (agent.MainTarget != null) { agent.AttackTarget = agent.MainTarget; state = CandiceBehaviorStates.SUCCESS; } else { Debug.LogError("CandiceDefaultBehaviors.SetAttackTarget: Main Target is NULL"); } } catch (Exception e) { state = CandiceBehaviorStates.FAILURE; Debug.LogError("CandiceDefaultBehaviors.SetAttackTarget: " + e.Message); } return(state); }
public void AddNode(CandiceBehaviorNode node) { m_nodes.Add(node); }
/* The constructor requires the child node that this CandiceBehaviorInverter decorator * wraps*/ public CandiceBehaviorInverter(CandiceBehaviorNode node) { m_node = node; }
/* Because this node contains no logic itself, * the logic must be passed in in the form of * a delegate. As the signature states, the action * needs to return a NodeStates enum */ public CandiceBehaviorAction(ActionNodeDelegate action, CandiceBehaviorNode rootNode) { this.rootNode = rootNode; m_action = action; }