Ejemplo n.º 1
0
    void Attack()
    {
        navAgent.velocity  = Vector3.zero; //Stop enemy completely
        navAgent.isStopped = true;         //Not allowed to move

        attackTimer += Time.deltaTime;

        //When attackTimer surpasses wait time, cue attack
        if (attackTimer > waitBeforeAttack)
        {
            anim.Attack();

            attackTimer = 0f;

            //Play attack sounds
            enemyAudio.PlayAttack();
        }

        //Check if player runs away
        //Give player space to run away
        if (Vector3.Distance(transform.position, target.position) > attackDistance + pursuitDistance)
        {
            enemyState = EnemyStates.CHASE;
        }
    }
Ejemplo n.º 2
0
    } // chase

    void Attack() {

        navAgent.velocity = Vector3.zero;
        navAgent.isStopped = true;

        attack_Timer += Time.deltaTime;

        if(attack_Timer > wait_Before_Attack) {

            enemy_Anim.Attack();

            attack_Timer = 0f;

            // play attack sound
            //enemy_Audio.Play_AttackSound();

        }

        if(Vector3.Distance(transform.position, target.position) >
           attack_Distance + chase_After_Attack_Distance) {

            enemy_State = EnemyState.CHASE;

        }


    } // attack
Ejemplo n.º 3
0
    private void Attack()
    {
        //Stop the enemy
        navMeshAgent.velocity  = Vector3.zero;
        navMeshAgent.isStopped = true;

        attackTimer += Time.deltaTime;

        if (attackTimer > waitBeforeAttack)
        {
            enemyAnimator.Attack();

            attackTimer = 0;

            //Play attack sound
            enemyAudio.PlayAttackSound();
        }

        //Make the enemy looking at the player at all time while attacking
        transform.LookAt(target.position);

        if (Vector3.Distance(transform.position, target.position) > attackDistance + chaseAfterAttackDistance)
        {
            enemyState = EnemyState.CHASE;
        }
    }
Ejemplo n.º 4
0
    }     // chase

    void Attack()
    {
        navAgent.velocity  = Vector3.zero;
        navAgent.isStopped = true;

        attack_Timer += Time.deltaTime;

        if (attack_Timer > wait_Before_Attack)
        {
            enemy_Anim.Attack();

            attack_Timer = 0f;

            float  damage = 5f;
            Target t      = GameObject.FindWithTag(Tags.PLAYER_TAG).transform.GetComponent <Target>();
            t.TakeDamage(damage);
            //enemy_Audio.Play_AttackSound();
        }

        if (Vector3.Distance(transform.position, target.position) >
            attack_Distance + chase_After_Attack_Distance)
        {
            enemy_State = EnemyState.CHASE;
        }
    } // attack
Ejemplo n.º 5
0
    private void Attack()
    {
        attackTimer += Time.deltaTime;
        if (attackTimer > waitBeforeAttack)
        {
            enemyAnimator.Attack();
            attackTimer = 0;
        }

        CheckChaseDistance();
    }
Ejemplo n.º 6
0
    void Update()
    {
        transform.LookAt(Player.transform);
        if (Vector3.Distance(transform.position, Player.transform.position) <= chase_Distance && Vector3.Distance(transform.position, Player.transform.position) > attack_Distance)
        {
            enemy_Anim.Walk(false);
            enemy_Anim.Run(true);
            transform.position += transform.forward * run_Speed * Time.deltaTime;
            audio.clip          = chase_audio;
            acumulateTime      += Time.deltaTime;
            if (last_state != "chase" || acumulateTime > nextAudioTime)
            {
                audio.Play();
                acumulateTime = 0f;
                Debug.Log("chase");
            }

            last_state = "chase";
        }
        else if (Vector3.Distance(transform.position, Player.transform.position) <= attack_Distance)
        {
            enemy_Anim.Run(false);
            enemy_Anim.Walk(false);

            //ENEMY ATACKS
            enemy_Anim.Attack();
            transform.position += transform.forward * 0 * Time.deltaTime;
            audio.clip          = attack_audio;
            acumulateTime      += Time.deltaTime;
            if (last_state != "attack" || acumulateTime > nextAudioTime)
            {
                audio.Play();
                acumulateTime = 0f;
                Debug.Log("attck");
            }
            last_state = "attack";
        }
        else
        {
            enemy_Anim.Walk(true);
            transform.position += transform.forward * walk_Speed * Time.deltaTime;
            audio.clip          = walk_audio;
            acumulateTime      += Time.deltaTime;
            if (last_state != "walk" || acumulateTime > nextAudioTime)
            {
                audio.Play();
                acumulateTime = 0f;
                Debug.Log("walk");
            }
            last_state = "walk";
        }
    }
    /// <summary>
    ///when the enemy goes to attack
    /// </summary>
    void Attack()
    {
        ////Detect player in range
        Collider[] hitPlayer = Physics.OverlapSphere(enemyAttackPoint.position, attackRange, playerLayer);

        animator.Attack();

        //Damage player
        foreach (Collider player in hitPlayer)
        {
            player.GetComponent <PlayerAttackBehavior>().TakeDamage(attack);
        }
    }
Ejemplo n.º 8
0
    void Attack()
    {
        navAgent.velocity  = Vector3.zero;
        navAgent.isStopped = true;

        attackTimer += Time.deltaTime;
        if (attackTimer > _waitBeforeAttack)
        {
            enemyAnim.Attack();
            attackTimer = 0f;
        }

        if (Vector3.Distance(transform.position, target.position) > _attackDistance + _chaseAfterAttack)
        {
            enemyState = EnemyState.CHASE;
        }
    }
Ejemplo n.º 9
0
    void Attack()
    {
        navMeshAgent.velocity  = Vector3.zero;
        navMeshAgent.isStopped = true;

        attackTimer += Time.deltaTime;
        if (attackTimer > waitBeforeAttack)
        {
            enemyAnimator.Attack();
            attackTimer = 0f;
            enemySounds.PlayAttackSound();
        }

        if (Vector3.Distance(transform.position, target.position) > attackDistance + chaseAfterAttackDistance)
        {
            enemyState = EnemyState.CHASE;
        }
    }
Ejemplo n.º 10
0
    private void Attack()
    {
        _navAgent.velocity  = Vector3.zero;
        _navAgent.isStopped = true;

        attactTimer += Time.deltaTime;

        if (attactTimer > waitBeforeAttack)
        {
            _enemyAnim.Attack();
            attactTimer = 0;

            _enemyAudio.PlayAttackSound();
        }
        if (Vector3.Distance(transform.position, _target.position) > attackDistance + chaseAfterAttackDistance)
        {
            _enemyState = EnemyState.CHASE;
        }
    }
Ejemplo n.º 11
0
    // Attack
    void Attack()
    {
        nav_mesh_agent.velocity  = Vector3.zero;
        nav_mesh_agent.isStopped = true;

        attack_timer += Time.deltaTime;

        if (attack_timer > wait_before_attack)
        {
            enemy_animat.Attack();
            attack_timer = 0f;
            // play attack sound
            //enemy_audio.Play_AttackSound();
        }

        if (Vector3.Distance(transform.position, target.position) >
            attack_distance + chase_after_attack_distance)
        {
            enemy_state = EnemyState.CHASE;
        }
    }
Ejemplo n.º 12
0
    private void Attack()
    {
        navMeshAgent.velocity  = Vector3.zero;
        navMeshAgent.isStopped = true;
        attackTimer           += Time.deltaTime;

        if (attackTimer > waitBeforeAttack)
        {
            enemyAnimator.Attack();
            attackTimer = 0f;

            // Play attack sound
            enemyAudio.AttackSound();
        }

        // Player runs away then chase him
        if (Vector3.Distance(transform.position, target.position) >
            (attackDistance + chaseAfterAttackDistance))
        {
            enemyState = EnemyState.CHASE;
        }
    }
 //function responsible for attacking the player
 void Attack()
 {
     //zombie has stopped moving
     navAgent.velocity  = Vector3.zero;
     navAgent.isStopped = true;
     //the timer for the zombie attacks
     attack_Timer += Time.deltaTime;
     //enough time has passed to attack the player
     if (attack_Timer > wait_Before_Attack)
     {
         // play attack sound
         enemyAudio.PlayAttackSound();
         //play the attack animation
         enemy_Anim.Attack();
         //reset the timer for the next attack
         attack_Timer = 0f;
     }
     //if the player flees, chase them
     if (Vector3.Distance(transform.position, target.position) >
         attack_Distance + chase_After_Attack_Distance)
     {
         enemy_State = EnemyState.CHASE;
     }
 }
Ejemplo n.º 14
0
    void Update()
    {
        if (enemy_State == EnemyState.PATROL)
        {
            Patrol();
        }
        if (enemy_State == EnemyState.ATTACK)
        {
            Attack();
        }
        if (enemy_State == EnemyState.CHASE)
        {
            Chase();
        }
        void Patrol()
        {
            navAgent.isStopped = false;
            navAgent.speed     = walk_Speed;
            patrol_Timer      += Time.deltaTime;
            if (patrol_Timer > patrol_For_This_Time)
            {
                SetNewRandomDestination();
                patrol_Timer = 0f;
            }
            if (navAgent.velocity.sqrMagnitude > 0)
            {
                enemy_Anim.Walk(true);
            }
            else
            {
                enemy_Anim.Walk(false);
            }
            if (Vector3.Distance(transform.position, target.position) <= chase_Distance)
            {
                enemy_Anim.Walk(false);
                enemy_State = EnemyState.CHASE;
                enemy_Audio.Play_ScreamSound();
            }
        }

        void Chase()
        {
            navAgent.isStopped = false;
            navAgent.speed     = run_Speed;
            navAgent.SetDestination(target.position);
            if (navAgent.velocity.sqrMagnitude > 0)
            {
                enemy_Anim.Run(true);
            }
            else
            {
                enemy_Anim.Run(false);
            }
            if (Vector3.Distance(transform.position, target.position) <= attack_Distance)
            {
                enemy_Anim.Run(false);
                enemy_State = EnemyState.ATTACK;
                if (chase_Distance != current_Chase_Distance)
                {
                    chase_Distance = current_Chase_Distance;
                }
            }
            else if (Vector3.Distance(transform.position, target.position) > chase_Distance)
            {
                enemy_Anim.Run(false);
                enemy_State  = EnemyState.PATROL;
                patrol_Timer = patrol_For_This_Time;
                if (chase_Distance != current_Chase_Distance)
                {
                    chase_Distance = current_Chase_Distance;
                }
            }
        }

        void Attack()
        {
            navAgent.velocity  = Vector3.zero;
            navAgent.isStopped = true;
            attack_Timer      += Time.deltaTime;
            if (attack_Timer > wait_Before_Attack)
            {
                enemy_Anim.Attack();
                attack_Timer = 0f;
                enemy_Audio.Play_AttackSound();
            }
            if (Vector3.Distance(transform.position, target.position) > attack_Distance + chase_After_Attack_Distance)
            {
                enemy_State = EnemyState.PATROL;
            }
        }

        void SetNewRandomDestination()
        {
            float   rand_Radius = Random.Range(patrol_Radius_Min, patrol_Radius_Max);
            Vector3 randDir     = Random.insideUnitSphere * rand_Radius;

            randDir += transform.position;
            NavMeshHit navHit;

            NavMesh.SamplePosition(randDir, out navHit, rand_Radius, -1);
            navAgent.SetDestination(navHit.position);
        }
    }