Exemplo n.º 1
0
 public void Stun(float stunDuration)
 {
     stunTimer = stunDuration;
     if (!enemy.GetComponent <Rigidbody>())
     {
         enemy.gameObject.AddComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
     }
 }
Exemplo n.º 2
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Enemy")
        {
            print("PPP");

            Instantiate(playerParticle, transform.position + new Vector3(0, 3, 0), Quaternion.identity);
            canRun         = false;
            enemyAi_Script = collision.gameObject.GetComponentInParent <EnemyAi>();

            foreach (var col in enemyAi_Script.All_Colliders)
            {
                col.enabled = true;
            }

            enemyAi_Script.Main_Collider.enabled = false;

            enemyAi_Script.enabled = false;
            enemyAi_Script.GetComponent <Animator>().enabled     = false;
            enemyAi_Script.GetComponent <Rigidbody>().useGravity = true;
            StartCoroutine("Run");
            //Rb.isKinematic = true;

            Destroy(enemyAi_Script.gameObject, 4f);
        }


        if (collision.gameObject.tag == "Wall")
        {
            //Rb.rotation = Quaternion.Euler(0,180,0);

            var speed     = lastVelocity.magnitude;
            var direction = Vector3.Reflect(lastVelocity.normalized, collision.contacts[0].normal);
            transform.eulerAngles = direction;
            Rb.velocity           = direction * Mathf.Max(speed, 0);
        }

        if (collision.gameObject.tag == "Breakable")
        {
            collision.gameObject.layer = LayerMask.NameToLayer("Pieces");
            //Rb.isKinematic = true;
            StartCoroutine("Breakable_Hit_Delay");
        }
    }
Exemplo n.º 3
0
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag(targetTag))
        {
            other.GetComponent <Vida> ().CambioDeVida(ataque);
            Quaternion rotacion = Quaternion.Euler(0, 0, 0);
            Instantiate(efectoAtaque, transform.position, rotacion);


            //
            Vector3 dir = other.transform.position - owner.transform.position;
            dir.y = 0;
            dir.Normalize();             // solo para normalizar y obtener la direccion del Vector

            // como este script sera usado tato por el player como por el enemigo
            // es posible que _enemyScript sea nulo
            EnemyAi _enemyScript = other.GetComponent <EnemyAi>();
            // debido a esto hacemos este chequeo para evitar errores
            if (_enemyScript != null)
            {
                _enemyScript.GetComponent <EnemyAi>().AddImpact(dir, fuerzaAtaque);
            }
        }
    }
Exemplo n.º 4
0
 public void death()
 {
     enemy.GetComponent <Rigidbody> ().isKinematic = false;
     enemy.GetComponent <GameObject>().SetActive(false);
 }
Exemplo n.º 5
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();
            }
        }
    }