Beispiel #1
0
        /***************************************************************************************************************
         *  Routine()  The aggroDistance is set via unity inspector.  If player enters the aggroDistance, . Once aggroed routine tracks if the NPC is chasing or close enough
         * to attack and calls the appropriate function
         ****************************************************************************************************************/

        public void routine()
        {
            if (isDazed == true) //dazed happens when boss charge hits a wall and when boss is hit by player's bomb
            {
                if (dazedTimer <= 0)
                {
                    isDazed = false;
                    AttackScript.charging = false;
                    Anim.SetBool("isCharging", false);
                }
                else
                {
                    CharRigidBody.Sleep();
                    dazedTimer--;
                }
            }
            else //if not dazed
            {
                if (distance > 5.5f) //chase player and try to charge if player is close to x or y axis of boss
                {
                    ChargeNoise.Play();
                    ChaseScript.Chase();
                    AttackScript.tryToCharge();
                }
                else
                {
                    StepNoise.Play();
                    ChaseScript.Chase();
                    if (distance <= 2.6f) //melee attack if close enough
                    {
                        AttackNoise.Play();
                        AttackScript.attack();
                    }
                }
            }
        }
Beispiel #2
0
        /***************************************************************************************************************
         *  Routine() keeps track if the enemy is aggroed yet via the distance arguement. The aggroDistance is set to default 5
         * but can also be set via unity inspector.  If player enters the aggroDistance, the patrol script's aggroed bool is set
         * to true and it's forces on the NPC rigidbody are removed. Once aggroed routine tracks if the NPC is chasing or close enough
         * to attack and calls the appropriate function
         ****************************************************************************************************************/

        public void routine(float distance)
        {
            // Vector3 raycastDir = transform.position - Player.transform.position;
            Vector3 fromPosition = transform.position;
            Vector3 toPosition   = Player.transform.position;

            //Adjusts the posistion the ray is being shot from to avoid hiting enemy's collider
            if (transform.position.y > Player.transform.position.y)
            {
                fromPosition.y -= 1;
            }
            else
            {
                fromPosition.y += 1;
            }
            if (transform.position.x > Player.transform.position.x)
            {
                fromPosition.x -= 1;
            }
            else
            {
                fromPosition.x += 1;
            }

            Vector3 direction = toPosition - fromPosition;

            Debug.DrawRay(fromPosition, direction, Color.white, 1.0f);

            //hit records the first collider hit by the ray
            RaycastHit2D hit = Physics2D.Raycast(fromPosition, direction);

            //Debug.Log(hit.collider.gameObject.tag);

            if ((distance <= aggroDistance) && (hit.collider.gameObject.tag == "Player") && (PatrolScript.aggroed == false))
            {
                PatrolScript.aggroed = true;
                EnemyHitAudio.clip   = AggroSound;
                EnemyHitAudio.Play();
                CharRigidBody.Sleep();//sleep resets the forces from the patrol script on the rigidbody 2d sorry for the hack
                PatrolScript.enabled = false;
            }

            if (PatrolScript.enabled == false) //Player has aggroed enemy
            {
                if (distance >= attackRange)
                {
                    ChaseScript.Chase(); //if aggroed keep moving
                }

                attackTimer -= 1; //always decrease attack timer
                if (attackTimer <= 0)
                {
                    canAttack = true;
                }

                if ((distance <= attackRange) && (canAttack)) //if in range for attack then attack
                {
                    Attack.Attack();
                    if (RangedAttackSound)
                    {
                        EnemyAttackAudio.clip = RangedAttackSound;
                    }
                    else
                    {
                        EnemyAttackAudio.clip = AttackSound;
                    }
                    EnemyAttackAudio.Play();
                    attackTimer = TimeBetweenEnemyAttacks;
                    canAttack   = false;
                }
            }
        }