Example #1
0
 void Attack()
 {
     agent.isStopped = true;
     anim.SetBool("Attack", true);
     if (Vector3.Distance(transform.position, target.transform.position) > 5)
     {
         currentState = IaState.Berserk;
     }
 }
Example #2
0
    void Hurt()//iframes
    {
        //agent.isStopped = true;

        //anim.SetTrigger("Hit");
        if (!iFrames)
        {
            currentState = IaState.Follow;
        }
    }
Example #3
0
 void Attack()//ataca o player e vai pra look
 {
     Debug.Log("attack");
     RotateTowards(target.transform);
     //anim.speed = 1;
     //agent.isStopped = true;//?
     StartCoroutine(AttackCol());
     anim.SetTrigger("Attack");
     currentState = IaState.Look;
 }
Example #4
0
    void Stopped()
    {
        agent.isStopped = true;
        anim.SetBool("Attack", false);

        if (target && Vector3.Distance(transform.position, target.transform.position) > distancetotrigger)
        {
            currentState = IaState.Patrol;
        }
    }
Example #5
0
 void Attack()
 {
     agent.isStopped = true;
     anim.SetBool("Attack", true);
     //se o jogador se afastar ele volta a perseguir
     if (Vector3.Distance(transform.position, target.transform.position) > distancetoattack + 2)
     {
         currentState = IaState.Berserk;
     }
 }
Example #6
0
 void Berserk()
 {
     agent.isStopped = false;
     agent.SetDestination(target.transform.position);
     anim.SetBool("Attack", false);
     if (Vector3.Distance(transform.position, target.transform.position) < 3)
     {
         currentState = IaState.Attack;
     }
 }
Example #7
0
 public float range;                //distancia q deve estar do jogador
 public void VerifyPlayerDistance() //verifica distancia do jogador e persegue
 {
     if (currentState == IaState.Dying || currentState == IaState.Stun)
     {
         CancelInvoke("VerifyPlayerDistance");
     }
     else if ((target.transform.position - transform.position).sqrMagnitude < range * range)
     {
         print((target.transform.position - transform.position).sqrMagnitude);
         currentState = IaState.Follow;
         CancelInvoke("VerifyPlayerDistance");
     }
 }
Example #8
0
 void Stun()//fica parado até o fim do tempo, troca de cor
 {
     enMat.color = Color.blue;
     enMat.SetColor("_EmissionColor", Color.blue);
     //agent.isStopped = true;
     anim.speed = 0;
     if (!stunFrames)
     {
         anim.speed  = 1;
         enMat.color = Color.white;
         enMat.SetColor("_EmissionColor", Color.white);
         currentState = IaState.Follow;
     }
 }
Example #9
0
    void Berserk()
    {
        agent.isStopped = false;
        agent.SetDestination(target.transform.position);
        anim.SetBool("Attack", false);
        //se a distancia dele for  menor q 3 ele ataca
        if (Vector3.Distance(transform.position, target.transform.position) < distancetoattack)
        {
            currentState = IaState.Attack;
        }

        //se a distancia dele for  maior q o trigger ele patrulha de novo
        if (Vector3.Distance(transform.position, target.transform.position) > distancetotrigger)
        {
            currentState = IaState.Patrol;
        }
    }
Example #10
0
 void OnTriggerEnter(Collider other)//detecta se foi atacado
 {
     if (!iFrames && !stunFrames && other.gameObject.CompareTag("Shot"))
     {
         if (HP > 0)
         {
             currentState = IaState.Hurt;
             HP--;
             StartCoroutine(IFrames());
             Destroy(other.gameObject);
         }
         else
         {
             currentState = IaState.Dying;//trocar pra dying
         }
     }
     else if (!iFrames && !stunFrames && other.gameObject.CompareTag("Sword"))
     {
         if (HP > 0)
         {
             currentState = IaState.Hurt;
             HP--;
             StartCoroutine(IFrames());
         }
         else
         {
             currentState = IaState.Dying;//trocar pra dying
         }
     }
     else if (!stunFrames && other.gameObject.CompareTag("StunAttack"))
     {
         if (HP > 0)
         {
             currentState = IaState.Stun;
             HP--;
             StartCoroutine(StunFrames());
         }
         else
         {
             currentState = IaState.Dying;//trocar pra dying
         }
     }
 }
Example #11
0
 void Patrol()
 {
     agent.isStopped = false;
     agent.SetDestination(patrolposition);
     anim.SetBool("Attack", false);
     //tempo parado
     if (agent.velocity.magnitude < 0.1f)
     {
         stoppedTime += Time.deltaTime;
     }
     //se for mais q timetowait segundos
     if (stoppedTime > timetowait)
     {
         stoppedTime    = 0;
         patrolposition = new Vector3(transform.position.x + Random.Range(-patrolDistance, patrolDistance), transform.position.y, transform.position.z + Random.Range(-patrolDistance, patrolDistance));
     }
     //ditancia do jogador for menor q distancetotrigger
     if (Vector3.Distance(transform.position, target.transform.position) < distancetotrigger)
     {
         currentState = IaState.Berserk;
     }
 }
Example #12
0
    void Patrol()
    {
        agent.isStopped = false;
        agent.SetDestination(patrolposition);
        anim.SetBool("Attack", false);
        //tempo parado
        if (agent.velocity.magnitude < 0.1f)
        {
            stoppedTime += Time.deltaTime;
        }
        //se for mais q 3 segundos
        if (stoppedTime > 3)
        {
            stoppedTime    = 0;
            patrolposition = new Vector3(transform.position.x + Random.Range(-10, 10), transform.position.y, transform.position.z + Random.Range(-10, 10));
        }

        if (Vector3.Distance(transform.position, target.transform.position) < 10)
        {
            currentState = IaState.Berserk;
        }
    }
Example #13
0
 // Start is called before the first frame update
 void Start()//pega varios componentes, randomiza velocidade do inimigos e das animações, define se o inimigo começa seguindo o jogador ou não
 {
     //attackCol = GameObject.FindGameObjectsWithTag("attackCol");
     //handColEsq = GameObject.Find("HandColEsq");
     //handColDir = GameObject.Find("HandColDir");
     //armColEsq = GameObject.Find("ArmColEsq");
     //armColDir = GameObject.Find("ArmColDir");
     playerDetect = transform.GetChild(2).gameObject;
     agent        = GetComponent <NavMeshAgent>();
     anim         = GetComponent <Animator>();
     agent.speed  = Random.Range(5, 20);
     anim.SetFloat("Velocity", agent.speed / 5);
     enMat       = GetComponentInChildren <Renderer>().material;
     enColliders = GetComponents <Collider>();
     rbEnemy     = GetComponent <Rigidbody>();
     if (agent.speed > 10)
     {
         //anim.SetInteger("SpeedVerifier", 2);
         currentFollow = FollowState.Run;
     }
     else
     {
         //anim.SetInteger("SpeedVerifier", 1);
         currentFollow = FollowState.Walk;
     }
     target = GameObject.FindGameObjectWithTag("Player");
     if (startAsleep)
     {
         currentState = IaState.Asleep;
         InvokeRepeating("VerifyPlayerDistance", 0.1f, 1.5f);
     }
     else
     {
         currentState = IaState.Follow;
     }
     //print(anim.speed);
 }
Example #14
0
    // Update is called once per frame
    void Update()//maquina de estado do inimigo e condição de animação de idle
    {
        if (!RespawnBrain.instance.gameState)
        {
            for (int i = 0; i < enColliders.Length; i++)
            {
                enColliders[i].enabled = false;
            }
            currentState = IaState.Asleep;
        }
        switch (currentState)
        {
        case IaState.Asleep:
            Asleep();
            break;

        case IaState.Follow:
            Follow();
            break;

        case IaState.Look:
            Look();
            break;

        case IaState.Attack:
            Attack();
            break;

        case IaState.Hurt:
            Hurt();
            break;

        case IaState.Stun:
            Stun();
            break;

        case IaState.Dying:
            Dying();
            break;
        }

        anim.SetFloat("Magnitude", agent.velocity.magnitude);

        /*if (anim.GetCurrentAnimatorStateInfo(1).IsName("Ataque"))
         * {
         *  for (int i = 0; i < attackCol.Length; i++)
         *  {
         *      attackCol[i].SetActive(true);
         *      Debug.Log("atkColOn");
         *  }
         * }
         * else
         * {
         *  for (int i = 0; i < attackCol.Length; i++)
         *  {
         *      attackCol[i].SetActive(false);
         *      Debug.Log("atkColOff");
         *  }
         *
         * }
         */
    }
Example #15
0
 public void ChangeState(IaState state)
 {
     m_state = state;
 }