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);
        }
Beispiel #2
0
        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 Wander(CandiceBehaviorNode rootNode)
        {
            CandiceAIController agent = rootNode.aiController;

            agent.Wander();
            return(CandiceBehaviorStates.SUCCESS);
        }
Beispiel #5
0
        public void MoveForwardWithSlopeAlignment(Transform transform, CandiceAIController aiController)
        {
            var     ray      = new Ray(transform.position, Vector3.down);
            Vector3 velocity = transform.forward;

            if (Physics.Raycast(ray, out RaycastHit hitInfo, aiController.HalfHeight + 0.2f))
            {
                var slopeRotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);
                velocity = slopeRotation * velocity;
            }
            transform.position += velocity * aiController.MoveSpeed * Time.deltaTime;
        }
        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 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 ScanForObjects(CandiceBehaviorNode rootNode)
 {
     try
     {
         CandiceAIController agent = rootNode.aiController;
         agent.ScanForObjects();
         return(CandiceBehaviorStates.SUCCESS);
     }
     catch (Exception ex)
     {
         Debug.LogError(ex.Message);
         return(CandiceBehaviorStates.FAILURE);
     }
 }
Beispiel #10
0
        // Start is called before the first frame update
        void Start()
        {
            aiController = GetComponent <CandiceAIController>();
            rootNode     = new CandiceBehaviorSequence();
            rootNode.Initialise(transform, aiController);

            /*
             * Uncomment to test out the different behaviours.
             * Remember, you can only have one of these functions running at a time.
             */
            AggressiveAIMelee();
            //AggressiveAIRanged();
            //WanderAI();
            //CowardAI();
        }
Beispiel #11
0
        public void RotateTo(Transform transform, CandiceAIController aiController)
        {
            float desiredAngle = 180;
            int   direction    = 1;
            float angle        = Vector3.Angle((aiController.MainTarget.transform.position - aiController.transform.position), aiController.transform.right);

            if (angle > 90)
            {
                angle = 360 - angle;
            }
            if (angle > desiredAngle)
            {
                direction = -1;
            }
            float rotation = (direction * aiController.RotationSpeed) * Time.deltaTime;

            aiController.transform.Rotate(0, rotation, 0);
        }
 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);
     }
 }
        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 Initialise(Transform transform, CandiceAIController aiController)
 {
     this.transform    = transform;
     this.aiController = aiController;
 }
Beispiel #15
0
 public void LookAway(Transform transform, CandiceAIController aiController)
 {
     transform.LookAt(-aiController.MainTarget.transform.forward);
 }
Beispiel #16
0
 public void LookAt(Transform transform, CandiceAIController aiController)
 {
     transform.LookAt(aiController.LookPoint);
 }
Beispiel #17
0
 public void Initialise(CandiceAIController aiController)
 {
     this.aiController = aiController;
 }
Beispiel #18
0
 public void MoveForward(Transform transform, CandiceAIController aiController)
 {
     transform.position += transform.forward * aiController.MoveSpeed * Time.deltaTime;
 }
Beispiel #19
0
        void AttachAIControllerScript()
        {
            //Assign AI Script to the GameObject
            if (attachRigidBody)
            {
                if (is3D)
                {
                    obj.AddComponent <Rigidbody>();
                }
                else
                {
                    obj.AddComponent <Rigidbody2D>();
                }
            }

            if (attachAnimator)
            {
                Animator a = obj.AddComponent <Animator>();
                a.applyRootMotion = false;
            }

            if (attachCollider)
            {
                if (is3D)
                {
                    switch (colliderTypeIndex)
                    {
                    case 0:
                        obj.AddComponent <CapsuleCollider>();
                        break;

                    case 1:
                        obj.AddComponent <BoxCollider>();
                        break;

                    case 2:
                        obj.AddComponent <SphereCollider>();
                        break;
                    }
                }
                else
                {
                    switch (colliderTypeIndex2D)
                    {
                    case 0:
                        obj.AddComponent <CapsuleCollider2D>();
                        break;

                    case 1:
                        obj.AddComponent <BoxCollider2D>();
                        break;

                    case 2:
                        obj.AddComponent <CircleCollider2D>();
                        break;
                    }
                }
            }
            obj.AddComponent <CandiceBehaviorTreeMono>();
            CandiceAIController aiScript = null;

            aiScript           = obj.AddComponent <CandiceAIController>();
            aiScript.Is3D      = is3D;
            aiScript.MoveSpeed = movementSpeed;
            if (isEnemy)
            {
                aiScript.EnemyTags.Add("Player");
            }
            aiScript.Rig           = rig;
            aiScript.EnableRagdoll = enableRagdoll;

            aiScript.AttackType         = attackType;
            aiScript.AttackRange        = m_AttackRange;
            aiScript.Projectile         = attackProjectile;
            aiScript.ProjectileSpawnPos = spawnPosition;
            aiScript.HasAttackAnimation = hasAttackAnimation;

            Selection.activeGameObject = obj;
            EditorUtility.DisplayDialog("Candice AI for Games", "Controller Setup Complete", "OK");
            Close();
        }