void UpdateAgro()
    {
        float distance = Vector2.Distance(centerEntity.position, targetFocus.transform.position);

        if (distance <= rayAgrooLenght)
        {
            AgroInfo agroInfo = CheckAgro();
            if (!agroInfo.hit)
            {
                bool lookingTarget = false;
                if ((targetFocus.transform.position.x > centerEntity.position.x) == stats.movingRight)
                {
                    lookingTarget = true;
                }

                if (distance <= statsAttack[0].attackRange && statsAttack[0].currentCooldown <= 0 && lookingTarget)
                {
                    statsAttack[0].currentCooldown  = statsAttack[0].cooldown;
                    statsAttack[1].currentCooldown += 1.2f;
                    animator.Play("AttackCac");
                    stats.actualAttack = 0;
                    SwitchToState(State.attackCac);
                }
                else if (distance >= statsAttack[0].attackRange + 2f && distance <= statsAttack[1].attackRange && statsAttack[1].currentCooldown <= 0 &&
                         targetFocus.GetCollisions().below&& !taupardBlock && lookingTarget)
                {
                    statsAttack[1].currentCooldown = statsAttack[1].cooldown;
                    animator.Play("AttackDist");
                    stats.actualAttack = 1;
                    SwitchToState(State.attackDist);
                }
                else
                {
                    if (distance <= rangeAgro && state != State.seeFocus && lookingTarget)
                    {
                        animator.Play("Idle");
                        SwitchToState(State.seeFocus);
                    }
                }
            }
            else
            {
                if (state == State.seeFocus)
                {
                    animator.Play("Idle");
                    SwitchToState(State.walking);
                }
            }
        }
        else if (state == State.seeFocus)
        {
            animator.Play("Idle");
            SwitchToState(State.walking);
        }
    }
Beispiel #2
0
    void UpdateAgro()
    {
        float distance = Vector2.Distance(eyes.position, targetCenter.position);

        if (distance <= rayAgrooLenght)
        {
            AgroInfo agroInfo = CheckAgro();
            if (!agroInfo.hit)
            {
                if (distance <= statsAttack[0].attackRange && statsAttack[0].currentCooldown <= 0)
                {
                    stats.movingRight = (agroInfo.directionRay.x > 0);
                    UpdateScale();
                    statsAttack[0].currentCooldown = statsAttack[0].cooldown;
                    animator.Play("AttackCac");
                    stats.actualAttack = 0;
                    SwitchToState(State.attackCac);
                    return;
                }
                if ((agroInfo.directionRay.x > 0) == stats.movingRight)
                {
                    if (distance >= statsAttack[0].attackRange && distance <= statsAttack[1].attackRange && statsAttack[1].currentCooldown <= 0)
                    {
                        statsAttack[1].currentCooldown = statsAttack[1].cooldown;
                        animator.Play("AttackDist");
                        stats.actualAttack = 1;
                        SwitchToState(State.attackDist);
                    }
                    else if (state != State.combat && state != State.blocked && !isStatic)
                    {
                        SwitchToState(State.combat);
                    }
                }
            }
        }
        else if (distance > rayAgrooLenght + 3f)
        {
            if (state == State.blocked || state == State.combat)
            {
                SwitchToState(State.walking);
            }
        }
    }
Beispiel #3
0
    void UpdateAttack()
    {
        RaycastHit2D hit;

        float factorVel = -1;

        if (stats.movingRight)
        {
            factorVel = 1;
        }

        if (controller.collisions.right || controller.collisions.left)
        {
            state = State.stun;
            animator.Play("Stun");
            stats.velocity = Vector2.zero;
            timerStun      = timeStun;
            return;
        }

        hit = GroundDetection();
        if (!hit)
        {
            Jump();
            haveJump = true;
        }
        else if (haveJump)
        {
            AgroInfo agroInfo = CheckAgro();
            if (agroInfo.hit || agroInfo.rayLenght > statsAttack.attackRange || (agroInfo.directionRay.x > 0) != stats.movingRight)
            {
                state = State.walking;
                animator.Play("Walk");
                haveJump = false;
            }
        }

        stats.velocity.x = speedAttack * factorVel;
    }
Beispiel #4
0
    bool UpdateAgro()
    {
        float distance = Vector2.Distance(eyes.position, targetFocus.transform.position);

        if (distance > statsAttack.attackRange)
        {
            return(false);
        }
        AgroInfo agroInfo = CheckAgro();

        if (!agroInfo.hit)
        {
            if ((agroInfo.directionRay.x > 0) == stats.movingRight && statsAttack.currentCooldown <= 0F)
            {
                statsAttack.currentCooldown = statsAttack.cooldown;
                state            = State.seeFocus;
                stats.velocity.x = 0F;
                return(true);
            }
        }
        return(false);
    }