Ejemplo n.º 1
0
    public void UpdateState()
    {
        if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.meleeAttackAvailable)
        {
            /*enemy.meleeFrontSwing = false;
             * enemy.meleeSwing = false;
             * enemy.meleeBackSwing = false;*/
            enemy.meleeAttackStart = false;
            enemy.meleeAttackEnd   = false;

            attacking   = true;
            damageDealt = false;
        }
        if (!attacking && enemy.navMeshAgent.remainingDistance >= enemy.navMeshAgent.stoppingDistance)      //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer
        {
            enemy.chase.EnterState();
        }

        if (attacking)
        {
            timer += Time.deltaTime;

            if (timer <= frontSwing)        //Front swing of the attack animation
            {
                /*if (!enemy.meleeFrontSwing)
                 *  enemy.meleeFrontSwing = true;*/
                if (!enemy.meleeAttackStart)
                {
                    enemy.meleeAttackStart = true;
                }

                if (enemy.IndicatorTemp)
                {
                    enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.yellow;
                }
                //Debug.Log("FRONT SWING");
            }
            else if (timer >= frontSwing && timer < frontSwing + attackTime)        //Beginning of the attack after front swing. Performs attack
            {
                /*enemy.meleeFrontSwing = false;
                 * if (!enemy.meleeSwing)
                 *  enemy.meleeSwing = true;*/

                if (enemy.IndicatorTemp)
                {
                    enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.red;
                }
                //Debug.Log("PERFORM ATTACK");
                if (!damageDealt)
                {
                    MeleeCollision(enemy.transform.position + enemy.transform.forward, 1);
                }
            }
            else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing)       //Back swing of the animation
            {
                /*enemy.meleeSwing = false;
                 * if (!enemy.meleeBackSwing)
                 *  enemy.meleeBackSwing = true;*/
                enemy.meleeAttacking   = true;
                enemy.MeleeRecovering  = true;
                enemy.meleeAttackStart = false;

                if (enemy.IndicatorTemp)
                {
                    enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.blue;
                }
                //Debug.Log("BACK SWING");
            }
            else if (timer >= frontSwing + attackTime + backSwing)      //End of attack animation.
            {
                //enemy.meleeBackSwing = false;
                enemy.meleeAttackEnd  = true;
                enemy.meleeAttacking  = false;
                enemy.MeleeRecovering = false;

                if (enemy.IndicatorTemp)
                {
                    enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.gray;
                }
                //Debug.Log("END ATTACK");
                enemy.StartMeleeCooldown();
                enemy.chase.EnterState();
            }
        }
        else
        {
            Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position);
            enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed);
            if (!enemy.CheckLineOfSight(rangedAttackBuffer))
            {
                enemy.chase.EnterState();
            }
        }
    }
Ejemplo n.º 2
0
    public void UpdateState()
    {
        if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.specialAttackAvailable)
        {
            /*enemy.specialFrontSwing = false;
             * enemy.specialSwing = false;
             * enemy.specialBackSwing = false;*/
            enemy.specialAttackStart = false;
            enemy.specialAttackEnd   = false;

            attacking          = true;
            projectileLaunched = false;
        }

        /*if (!attacking && enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance)      //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer
         * {
         *  enemy.chase.EnterState();
         * }*/

        if (attacking)
        {
            timer += Time.deltaTime;

            if (timer <= frontSwing)        //Front swing of the attack animation
            {
                /*if (!enemy.specialFrontSwing)
                 *  enemy.specialFrontSwing = true;*/
                if (!enemy.specialAttackStart)
                {
                    enemy.specialAttackStart = true;
                }

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.yellow;

                //Debug.Log("FRONT SWING");
            }
            else if (timer >= frontSwing && timer < frontSwing + attackTime)        //Beginning of the attack after front swing. Performs attack
            {
                /*enemy.specialFrontSwing = false;
                 * if (!enemy.specialSwing)
                 *  enemy.specialSwing = true;*/
                enemy.specialAttacking = true;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.red;

                if (!projectileLaunched)
                {
                    Vector3    temp             = new Vector3(enemy.transform.position.x, enemy.transform.position.y + enemy.transform.lossyScale.y, enemy.transform.position.z);
                    Vector3    tempPos          = new Vector3(enemy.transform.position.x, enemy.transform.position.y + (enemy.transform.lossyScale.y * 0.5f), enemy.transform.position.z) + enemy.transform.forward * 0.5f;
                    GameObject rangedProjectile = enemy.ShootProjectile(enemy.target.GetChild(0).position - tempPos, projectileSpeed);
                    rangedProjectile.GetComponent <EnemyProjectile>().knockback = enemy.specialKnockback;
                    projectileLaunched = true;
                }

                //Debug.Log("ATTACK");
            }
            else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing)       //Back swing of the animation
            {
                enemy.specialRecovering  = true;
                enemy.specialAttackStart = false;

                /*enemy.specialSwing = false;
                 * if (!enemy.specialBackSwing)
                 *  enemy.specialBackSwing = true;*/

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.blue;


                //Debug.Log("BACK SWING");
            }
            else if (timer >= frontSwing + attackTime + backSwing)      //End of attack animation.
            {
                //enemy.specialBackSwing = false;
                enemy.specialAttackEnd  = true;
                enemy.specialAttacking  = false;
                enemy.specialRecovering = false;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.gray;
                //Debug.Log("END ATTACK");
                enemy.StartSpecialCooldown();
                if (RollRandom.RollForProbability(enemy.specialAttackContinueProbability) && enemy.navMeshAgent.remainingDistance > enemy.navMeshAgent.stoppingDistance)
                {
                    enemy.special.EnterState();
                }
                else
                {
                    enemy.chase.EnterState();
                }
            }
        }
        else
        {
            Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position);
            enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed);
            if (!enemy.CheckLineOfSight(rangedAttackBuffer))
            {
                enemy.chase.EnterState();
            }
        }
    }
Ejemplo n.º 3
0
    public void UpdateState()
    {
        if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.specialAttackAvailable)
        {
            /*enemy.specialFrontSwing = false;
             * enemy.specialSwing = false;
             * enemy.specialBackSwing = false;*/
            enemy.specialAttackStart = false;
            enemy.specialAttackEnd   = false;

            attacking   = true;
            lungeDir    = enemy.transform.forward;
            damageDealt = false;
        }
        if (!attacking && enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance)      //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer
        {
            enemy.chase.EnterState();
        }

        if (attacking)
        {
            timer += Time.deltaTime;

            if (timer <= frontSwing)        //Front swing of the attack animation
            {
                /*if (!enemy.specialFrontSwing)
                 *  enemy.specialFrontSwing = true;*/
                if (!enemy.specialAttackStart)
                {
                    enemy.specialAttackStart = true;
                }

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.yellow;
            }
            else if (timer >= frontSwing && timer < frontSwing + attackTime)        //Beginning of the attack after front swing. Performs attack
            {
                /*enemy.specialFrontSwing = false;
                 * if (!enemy.specialSwing)
                 *  enemy.specialSwing = true;*/

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.red;
                if (!enemy.GetComponent <Rigidbody>())
                {
                    enemy.gameObject.AddComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
                }
                enemy.navMeshAgent.enabled = false;

                enemy.lunging = true;
                enemy.GetComponent <Rigidbody>().velocity = lungeDir * Time.deltaTime * lungeSpeed;
            }
            else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing)       //Back swing of the animation
            {
                /*enemy.specialSwing = false;
                 * if (!enemy.specialBackSwing)
                 *  enemy.specialBackSwing = true;*/
                enemy.specialAttacking   = true;
                enemy.specialRecovering  = true;
                enemy.specialAttackStart = false;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.blue;
                enemy.navMeshAgent.enabled = true;
                enemy.lunging = false;
                //Debug.Log("BACK SWING");
            }
            else if (timer >= frontSwing + attackTime + backSwing)      //End of attack animation.
            {
                //enemy.specialBackSwing = false;
                enemy.specialAttackEnd  = true;
                enemy.specialAttacking  = false;
                enemy.specialRecovering = false;

                //if (enemy.IndicatorTemp)
                //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.gray;
                //Debug.Log("END ATTACK");
                enemy.StartSpecialCooldown();
                if (RollRandom.RollForProbability(enemy.specialAttackContinueProbability) && enemy.navMeshAgent.remainingDistance > enemy.navMeshAgent.stoppingDistance)
                {
                    enemy.special.EnterState();
                }
                else
                {
                    enemy.chase.EnterState();
                }
            }
        }
        else
        {
            enemy.lunging = false;
            Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position);
            enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed);
            if (!enemy.CheckLineOfSight(rangedAttackBuffer))
            {
                enemy.chase.EnterState();
            }
        }
    }