Beispiel #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (target == null)
        {
            speed = 0;
            return;
        }
        animator.SetBool("onAttack", onAttack);
        animator.SetBool("onCharge", onCharge);

        if (path == null)
        {
            return;
        }
        if (currentWaypoint >= path.vectorPath.Count)
        {
            return;
        }
        Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] - rb.position).normalized;

        if (!onCharge && !enemyScriptHit.isHit)
        {
            rb.velocity = (direction * speed * Time.fixedDeltaTime);
        }
        else if (!enemyScriptHit.isHit)
        {
            rb.velocity = (directionCharge * speed * Time.fixedDeltaTime);
        }

        //Parte experimental knockback.
        //Feito aqui pois este script lida com velocidade.
        //Coma o knockback se nao tinha comecado já, e temos um hit.
        if (enemyScript.hit)
        {
            enemyScript.DealKnockback(1);
        }

        //lida com o timer do knockback
        enemyScript.DealKnockback(0);

        //Faz as modificacoes de velocidade necessarias
        //Adiciona o knockback se tiver, faz nada caso o contrário - ja que a velocidade "base" é definida acima.
        enemyScript.KnockBackProgrssion();

        if (enemyScript.isDead)
        {
            rb.velocity = new Vector2(0, 0);
        }

        float distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);

        if (direction.x >= 0.01f)
        {
            transform.localScale = new Vector3(1f, 1f, 1f);
        }
        else if (direction.x <= -0.01f)
        {
            transform.localScale = new Vector3(-1f, 1f, 1f);
        }



        if (enemyScript.health > 0)
        {
            if (!onChase && !onAttack && !onCharge)
            {
                checkIfInSight();
            }
            // checkando se está em um range para atacar
            if (!onAttack && !onCharge)
            {
                checkIfInAttackRange();
            }
            checkIfOnCharge();
            checkIfCanCharge();
            resetAfterCharge();



            if (distance < nextWaypointDistance)
            {
                currentWaypoint++;
            }
            /* verificando tempo de troca pontos para se andar (para fazer patroling) */
            if (Time.time - lastTime >= timeChangePoint && !onChase && !onAttack)
            {
                getRandomPoint();
                lastTime = Time.time;
            }
        }
        else
        {
            speed  = 0.0f;
            target = null;
        }
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        animator.SetBool("isCharging", isCharging);
        if (target == null)
        {
            return;
        }

        // essas parte é para definir para onde o personagem está atirando
        Vector2 auxVector  = (firePoint.position);
        Vector2 auxVector2 = (player.position);

        lookDir = auxVector2 - auxVector;

        roateWeapon();
        if (path == null)
        {
            return;
        }
        if (currentWaypoint >= path.vectorPath.Count)
        {
            return;
        }
        Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] - rb.position).normalized;


        if (!enemyScriptHit.isHit)
        {
            rb.velocity = (direction * speed * Time.fixedDeltaTime);
        }
        // rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime);

        //Parte experimental knockback.
        //Feito aqui pois este script lida com velocidade.
        //Coma o knockback se nao tinha comecado já, e temos um hit.
        if (enemyScript.hit)
        {
            enemyScript.DealKnockback(1);
        }

        //lida com o timer do knockback
        enemyScript.DealKnockback(0);

        //Faz as modificacoes de velocidade necessarias
        //Adiciona o knockback se tiver, faz nada caso o contrário - ja que a velocidade "base" é definida acima.
        enemyScript.KnockBackProgrssion();

        if (enemyScript.isDead)
        {
            rb.velocity = new Vector2(0, 0);
        }


        float distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);

        if (distance < nextWaypointDistance)
        {
            currentWaypoint++;
        }

        if (direction.x >= 0.01f)
        {
            transform.localScale = new Vector3(1f, 1f, 1f);
        }
        else if (direction.x <= -0.01f)
        {
            transform.localScale = new Vector3(-1f, 1f, 1f);
        }


        if (enemyScript.health > 0)
        {
            if (!onChase)
            {
                checkIfInSight();
            }
            slow_when_preper_to_shoot();
            if (onChase)
            {
                roateWeapon();
                if (Time.time - lastTimeShoot > timeBetweenShoots && Random.Range(0, 10) == 2)
                {
                    ShootShotgun();
                    speed         = speedIni;
                    lastTimeShoot = Time.time;
                }
            }



            /* verificando tempo de troca pontos para se andar (para fazer patroling) */
            if (Time.time - lastTime >= timeChangePoint && !onChase)
            {
                getRandomPoint();
                lastTime = Time.time;
            }
        }
        else
        {
            speed  = 0.0f;
            target = null;
        }
    }