Exemplo n.º 1
0
    //Ataque
    private void AtackState()
    {
        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), Time.deltaTime * rotSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

        if (audio)
        {
            if (!audio.isPlaying)
            {
                audio.PlayOneShot(sound, 0.6f);
            }
        }

        if (dir.magnitude < distanceToAttack)
        {
            crawl     = false;
            crawlFast = false;
            atack     = true;
        }
        else if (dir.magnitude > distanceToAttack && dir.magnitude <= distanceToReturnChase)
        {
            state = FSMStates.Chasing;
        }
        else if (dir.magnitude > distanceToReturnChase)
        {
            SetClosestWayPoint();
            state = FSMStates.Waypoints;
        }
    }
Exemplo n.º 2
0
    //Waypoints
    private void WaypointState()
    {
        crawl     = true;
        crawlFast = false;
        atack     = false;

        // Verifica se está na distância para perseguir
        if (dir.magnitude <= distanceToStartChasing && playerControl.safe == false)
        {
            state = FSMStates.Chasing;
            return;
        }
        // Descobre o caminho para o próximo Waypoint,
        // Gira para a direção dele
        Vector3 wpDir = waypoints [currentWaypoint].position - transform.position;

        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(wpDir), Time.deltaTime * rotSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
        if (wpDir.magnitude <= distanceToChangeWaypoint)
        {
            currentWaypoint++;
            if (currentWaypoint >= waypoints.Length)
            {
                currentWaypoint = 0;
            }
        }
        else
        {
            transform.Translate(0, 0, speed * Time.deltaTime);
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        distanceToPlayer = Vector3.Distance(transform.position, player.transform.position);
        health           = enemyHealth.currentHealth;

        if (health <= 0)
        {
            currentState = FSMStates.Die;
        }

        switch (currentState)
        {
        case FSMStates.Patrol:
            UpdatePatrolState();
            break;

        case FSMStates.Chase:
            UpdateChaseState();
            break;

        case FSMStates.Attack:
            UpdateAttackState();
            break;

        case FSMStates.Die:
            UpdateDieState();
            break;

        default:
            break;
        }
    }
Exemplo n.º 4
0
    IEnumerator ResetStates()
    {
        yield return(new WaitForSeconds(1));

        state    = FSMStates.Patrol;
        returned = false;
    }
Exemplo n.º 5
0
    private void WaypointState()
    {
        // Check if target is in range to chase
        if (dir.magnitude <= distanceToStartChasing)
        {
            state = FSMStates.Chasing;
            return;
        }

        // Find the direction to the current waypoint,
        //   rotate and move towards it
        Vector3 wpDir = waypoints[currentWaypoint].position - transform.position;

        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(wpDir), Time.deltaTime * rotSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
        if (wpDir.magnitude <= distanceToChangeWaypoint)
        {
            currentWaypoint++;
            if (currentWaypoint >= waypoints.Length)
            {
                currentWaypoint = 0;
            }
        }
        else
        {
            rb.MovePosition(transform.position + transform.forward * speed * Time.deltaTime);
        }
    }
Exemplo n.º 6
0
    // ReSharper disable Unity.PerformanceAnalysis
    private void UpdateLootState()
    {
        anim.SetInteger("animState", 1);

        agent.stoppingDistance = 0;

        agent.speed = 3.5f;

        if (Vector3.Distance(transform.position, nextLootDestination) <= 2)
        {
            currentState = FSMStates.Store;
        }
        else if (distanceToPlayer <= chaseDistance && IsPlayerInClearFOV())
        {
            currentState = FSMStates.Chase;
        }
        else if (beenHit)
        {
            nextDestination = player.transform.position;
            FaceTarget(nextDestination);
            agent.SetDestination(nextDestination);
            agent.speed = 5.0f;
            anim.SetInteger("animState", 2);
        }

        FaceTarget(nextLootDestination);
        agent.SetDestination(nextLootDestination);
    }
Exemplo n.º 7
0
    //executa quando acaba a animaçao sugar a vida do player

    public void DrainLifeEnd()
    {
        DrainingLife = false;
        ParticleSystem particleemitter = part.GetComponent <ParticleSystem>();

        if (particleemitter != null)
        {
            ParticleSystem.EmissionModule emit = particleemitter.emission;
            emit.enabled = false;
        }
        Destroy(part, 5f);

        //VidaTatu.GetComponent<LifePos>().Player.GetComponent<Life>().LifeQuant -= 100;

        //  VidaTatu.GetComponent<LifePos>().Player.GetComponent<Life>().UpdateL1 = true;


        Descer();
        MoveSpeed = 4f;


        MosquitoAni.SetBool("GoingToWorld", true);
        MosquitoAni.SetBool("LifeDrain", false);
        state = FSMStates.GoToWorld;
    }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        distanceToPlayer = Vector3.Distance(transform.position, player.transform.position);

        health = enemyHealth.currentHealth;

        switch (currentState)
        {
        case FSMStates.Patrol:
            UpdatePatrolState();
            break;

        case FSMStates.Chase:
            UpdateChaseState();
            break;

        case FSMStates.Attack:
            UpdateAttackState();
            break;

        case FSMStates.Dead:
            UpdateDeadState();
            break;
        }

        elapsedTime += Time.deltaTime;

        if (health <= 0)
        {
            currentState = FSMStates.Dead;
        }
    }
Exemplo n.º 9
0
    public void PerformTransition(Transition trans)
    {
        // Check for NullTransition before changing the current state
        if (trans == Transition.None)
        {
            Debug.LogError("FSM ERROR: Null transition is not allowed");
            return;
        }

        // Check if the currentState has the transition passed as argument
        FSMStateID id = currentState.GetOutputState(trans);

        if (id == FSMStateID.None)
        {
            Debug.LogError("FSM ERROR: Current State does not have a target state for this transition");
            return;
        }

        // Update the currentStateID and currentState
        currentStateID = id;
        foreach (FSMStates state in fsmStates)
        {
            if (state.ID == currentStateID)
            {
                currentState = state;
                break;
            }
        }
    }
Exemplo n.º 10
0
    private void ShootState()
    {
        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), Time.deltaTime * rotSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

        timer += Time.deltaTime;
        if (timer >= frequency)
        {
            timer = 0;

            Rigidbody b = GameObject.Instantiate(bullet, muzzle.position, muzzle.rotation) as Rigidbody;
            b.AddForce(muzzle.forward * bulletInitialForce);
            //GameObject.FindWithTag("soundcontrol").GetComponent<SoundControl>().PlaySound("shoot");

            numberOfShoots++;
            if (numberOfShoots >= maxNumberOfShoots)
            {
                if (dir.magnitude < distanceToAttack)
                {
                    numberOfShoots = 0;
                }
                else if (dir.magnitude > distanceToAttack && dir.magnitude <= distanceToReturnChase)
                {
                    state = FSMStates.Chasing;
                }
                else if (dir.magnitude > distanceToReturnChase)
                {
                    state = FSMStates.Waypoints;
                }
            }
        }
    }
Exemplo n.º 11
0
    void UpdateAttack()
    {
        FaceTarget(player.transform.position);

        HandleAttack();

        // Checks if player is now out of range.
        if (distanceToPlayer > attackRange &&
            distanceToPlayer <= detectionRange)
        {
            currentState = FSMStates.Chase;
            hasSwung     = false;
            attackTime   = 0;
            anim.SetInteger("ActiveState", 1);
        }
        else if (distanceToPlayer > detectionRange)
        {
            if (noPatrol)
            {
                currentState = FSMStates.Idle;
                hasSwung     = false;
                attackTime   = 0;
                anim.SetInteger("ActiveState", 0);
            }
            else
            {
                currentState = FSMStates.Patrol;
                hasSwung     = false;
                attackTime   = 0;
                anim.SetInteger("ActiveState", hasRunAnim ? 0 : 1);
            }
        }
    }
Exemplo n.º 12
0
 public void Alert(Transform target, bool initialEnemy)
 {
     if (state != FSMStates.Alerted && state != FSMStates.GameOver)
     {
         if (initialEnemy)
         {
             audioSource.clip = spotted;
             audioSource.Play();
             playReturn = true;
             var enemies = FindObjectsOfType <EnemyAI>();
             foreach (EnemyAI enemy in enemies)
             {
                 if (enemy != this)
                 {
                     enemy.Alert(target, false);
                 }
             }
         }
         else
         {
             playReturn = false;
         }
         alertTarget = target.transform.position;
         state       = FSMStates.Alerted;
         alertTime   = alertDuration;
     }
 }
Exemplo n.º 13
0
    private void WaypointState()
    {
        // Check if target is in range to chase
        if (dir.magnitude <= distanceToStartChasing)
        {
            state = FSMStates.Chasing;
            return;
        }

        // Find the direction to the current waypoint,
        //   rotate and move towards it
        Vector3 wpDir = waypoints[currentWaypoint].position - transform.position;

        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(wpDir), Time.deltaTime * rotSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
        if (wpDir.sqrMagnitude <= distanceToChangeWaypoint)
        {
            currentWaypoint++;
            if (currentWaypoint >= waypoints.Length)
            {
                //GameObject.FindWithTag("ListeneeAnim").GetComponent<AnimationEnemy>().Ativa(2);
                //GameObject.FindWithTag("Cisco").GetComponent<FSMCisco>().enabled = false;
            }
        }
        else
        {
            rb.MovePosition(transform.position + transform.forward * speed * Time.deltaTime);
        }
    }
Exemplo n.º 14
0
    void UpdateBattleState()
    {
        anim.SetInteger("animState", 1);

        if (rangedAttack && distanceToPlayer <= rangedAttackDistance)
        {
            currentState = FSMStates.AttackRanged;
        }
        else if (distanceToPlayer <= chaseDistance)
        {
            currentState = FSMStates.Chase;
        }
        else if (distanceToPlayer > detectionRange)
        {
            currentState = FSMStates.Idle;
        }

        FaceTarget(player.transform.position);

        if (!rangedAttack)
        {
            agent.speed = originalSpeed * 0.1f;
            agent.SetDestination(player.transform.position);
        }
        else
        {
            agent.SetDestination(player.transform.position);
        }

        //transform.position = Vector3.MoveTowards(transform.position, player.transform.position, enemySpeed * 0.1f * Time.deltaTime);
    }
Exemplo n.º 15
0
    private void UpdateMovingState()
    {
        anim.SetInteger("AnimState", 1);

        if (distToPlayer <= attackDistance)
        {
            currentState = FSMStates.Attacking;
        }
        else
        {
            if (distToPlayer <= chaseDistance && isPlayerInClearFOV())
            {
                print("Chasing");
                nextDestination = player.transform.position;
            }
            else
            {
                print("Patrolling");
                if (Vector3.Distance(transform.position, nextDestination) < 2)
                {
                    FindNextPoint();
                }
            }

            agent.stoppingDistance = 0;
            agent.speed            = 3.5f;

            FaceTarget(nextDestination);
            agent.SetDestination(nextDestination);
        }
    }
Exemplo n.º 16
0
 public void Inital()
 {
     fsmStates = new FSMStates();
     fsmStates.AddStateType(GetStateType((int)StateType.AttackType));
     fsmStates.AddStateType(GetStateType((int)StateType.MoveType));
     fsmStates.AddStateType(GetStateType((int)StateType.JumpingType));
     #region AddAttackStates
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack1), (int)AttackType.attack1);
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack2), (int)AttackType.attack2);
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack3), (int)AttackType.attack3);
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack4), (int)AttackType.attack4);
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack5), (int)AttackType.attack5);
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack6), (int)AttackType.attack6);
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack_first2), (int)AttackType.attack_first2);
     fsmStates.AddStates(GetStateType((int)StateType.AttackType),
                         GetStateAttackType((int)AttackType.attack_kick), (int)AttackType.attack_kick);
     #endregion
     #region AddMoveType
     fsmStates.AddStates(GetStateType((int)StateType.MoveType), GetStateMoveType((int)MoveType.Idle), (int)MoveType.Idle);
     fsmStates.AddStates(GetStateType((int)StateType.MoveType), GetStateMoveType((int)MoveType.Walk), (int)MoveType.Walk);
     fsmStates.AddStates(GetStateType((int)StateType.MoveType), GetStateMoveType((int)MoveType.Run), (int)MoveType.Run);
     #endregion
     #region AddJumpingType
     fsmStates.AddStates(GetStateType((int)StateType.JumpingType), GetStateJumpingType((int)JumpingType.Jump_Stand_Start), (int)JumpingType.Jump_Stand_Start);
     fsmStates.AddStates(GetStateType((int)StateType.JumpingType), GetStateJumpingType((int)JumpingType.Jump_Running_Start), (int)JumpingType.Jump_Running_Start);
     fsmStates.AddStates(GetStateType((int)StateType.JumpingType), GetStateJumpingType((int)JumpingType.Jump_Stand_End_02), (int)JumpingType.Jump_Stand_End_02);
     #endregion
 }
Exemplo n.º 17
0
    //estado do mosquito indo atraz do player
    #region Walk
    private void Walk()
    {
        MosquitoAni.SetBool("IsParolling", false);
        MosquitoAni.SetBool("FightingWalk", true);
        Vector3 dir = Target.transform.position;

        //rotaciona o Npc apontando para o alvo
        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Target.transform.position - myTransform.position), Time.deltaTime * RotationSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

        if (Distace > EnemyDist && Vector3.Distance(Target.transform.position, gameObject.transform.position) < SafeDist)
        {
            //Move o Npc para o alvo;
            rb.MovePosition(transform.position + transform.forward * Time.deltaTime * MoveSpeed);
        }

        TimerAtk += Time.deltaTime;
        if (Distace <= EnemyDist && TimerAtk >= CooldownAtk)
        {
            state    = FSMStates.ATK1;
            TimerAtk = 0;
        }

        if (Distace > SafeDist + 1)
        {
            MosquitoAni.SetBool("FightingWalk", false);
            state = FSMStates.Patrol;
        }

        if (TakeDamage)
        {
            state = FSMStates.Damage;
        }
    }
Exemplo n.º 18
0
    //executado quado esta patrulhando
    #region Idle
    private void Idle()
    {
        MosquitoAni.SetBool("IsIdle", true);

        //Verifica se o player entrou no alcance da visao do mosquito
        if (Vector3.Distance(Target.transform.position, gameObject.transform.position) < Vision)
        {
            MosquitoAni.SetBool("IsIdle", false);
            state = FSMStates.Walk;
        }
        TimeToNextPoint -= Time.deltaTime;
        if (TimeToNextPoint < 0)
        {
            currentWayPoint++;
            if (currentWayPoint >= waypoints.Length)
            {
                currentWayPoint = 0;
            }
            TimeToNextPoint = TimeTo;

            MosquitoAni.SetBool("IsIdle", false);
            state = FSMStates.Patrol;
        }

        if (TakeDamage)
        {
            state = FSMStates.Damage;
        }
    }
Exemplo n.º 19
0
    //faz o mosquito ir para a tela

    void goToScreen()
    {
        if (!reachScreen)
        {
            transform.localPosition = Vector3.MoveTowards(transform.localPosition, new Vector3(camScreen.localPosition.x + _2dX,
                                                                                               camScreen.localPosition.y + _2dY, camScreen.localPosition.z), velTransicao);
            //rotação pra deixar o modelo pronto pra movimentação na tela e colocar os pés do modelo no "vidro"
            ModelMosquito.transform.localEulerAngles = Vector3.MoveTowards(ModelMosquito.transform.localEulerAngles, new Vector3(90, 0, 0), velTransicao * 10);
            transform.localRotation = Quaternion.RotateTowards(transform.localRotation, Quaternion.AngleAxis(90, Vector3.right), velTransicao * 10);
            transform.localScale    = Vector3.MoveTowards(transform.localScale, new Vector3(0.5f, 0.5f, 0.5f), velTransicao / 10);
            if (transform.localPosition == new Vector3(camScreen.localPosition.x + _2dX, camScreen.localPosition.y + _2dY, camScreen.localPosition.z) && transform.localRotation == Quaternion.AngleAxis(90, Vector3.right) && transform.localScale == new Vector3(0.5f, 0.5f, 0.5f))
            {
                transform.localPosition = new Vector3(camScreen.localPosition.x + _2dX, camScreen.localPosition.y + _2dY, camScreen.localPosition.z);
                transform.localRotation = Quaternion.AngleAxis(90, Vector3.right);
                rb.velocity             = Vector3.zero;
                reachScreen             = true;
            }
        }

        //se o jogador pedir pra descer
        if (descer)
        {
            //tira ele do parent, ativa a variavel que fala que é pra ir pro 3D, liga a gravidade, e desativa a variavel que fala q ele ta na tela
            //SetAnimOffScreen();
            transform.SetParent(null);
            toWorld     = true;
            reachScreen = false;
            onScreen    = false;
            state       = FSMStates.Fall;
        }
    }
Exemplo n.º 20
0
    private void UpdatePatrolState()
    {
        anim.SetInteger("animState", 1);

        agent.stoppingDistance = 0;

        agent.speed = 3.5f;

        if (enemyType == AttackType.Ranged)
        {
            if (Vector3.Distance(transform.position, nextDestination) <= 2)
            {
                FindNextPoint();
            }
            else if (distanceToPlayer <= chaseDistance && IsPlayerInClearFOV())
            {
                currentState = FSMStates.RangedChase;
            }
            else if (beenHit)
            {
                nextDestination = player.transform.position;
                FaceTarget(nextDestination);
                agent.SetDestination(nextDestination);
                agent.speed = 5.0f;
                anim.SetInteger("animState", 2);
            }

            FaceTarget(nextDestination);
            agent.SetDestination(nextDestination);
        }
    }
Exemplo n.º 21
0
    void UpdateAttackState()
    {
        anim.SetInteger("animState", 3);

        if (distanceToPlayer > attackDistance)
        {
            if (distanceToPlayer <= chaseDistance)
            {
                currentState = FSMStates.Chase;
            }
            else if (rangedAttack && distanceToPlayer <= rangedAttackDistance)
            {
                currentState = FSMStates.AttackRanged;
            }
        }
        else if (distanceToPlayer > chaseDistance && distanceToPlayer <= detectionRange)
        {
            currentState = FSMStates.Battle;
        }
        else if (distanceToPlayer > detectionRange)
        {
            currentState = FSMStates.Idle;
        }

        FaceTarget(player.transform.position);
    }
Exemplo n.º 22
0
    void UpdateChase()
    {
        anim.SetInteger("ActiveState", 1);
        FaceTarget(player.transform.position);

        if (nav.enabled)
        {
            nav.SetDestination(player.transform.position);
            nav.stoppingDistance = attackRange;
            nav.speed            = chaseSpeed;
        }

        if (distanceToPlayer <= attackRange)
        {
            currentState = FSMStates.Attack;
            anim.SetInteger("ActiveState", 2);
        }
        else if (distanceToPlayer > detectionRange)
        {
            if (noPatrol)
            {
                if (willFlee)
                {
                    Debug.Log("Idle from chase");
                }
                currentState = FSMStates.Idle;
            }
            else
            {
                currentState = FSMStates.Patrol;
            }
        }
    }
Exemplo n.º 23
0
    void UpdateChaseState()
    {
        animator.SetInteger("animState", 2);

        agent.stoppingDistance = attackDistance;

        agent.speed = 6f;

        var playerPosition = player.transform.position;

        if (distanceToPlayer <= attackDistance)
        {
            countdown    = 0;
            attack       = true;
            currentState = FSMStates.Attack;
        }
        else if (distanceToPlayer > chaseDistance)
        {
            GetNextWanderPoint();
            currentState = FSMStates.Patrol;
        }

        FaceTarget(playerPosition);

        agent.SetDestination(playerPosition);
    }
Exemplo n.º 24
0
    // attacks and deals damage to player when within attack range
    // and player is in front of an enemy at a certain angle
    void HandleAttack()
    {
        // Handles successful attack.
        attackTime += Time.deltaTime;
        if (attackTime > timeToDamage && !hasSwung) // When to deal damage based on animation
        {
            // calculates if enemy is facing player
            Vector3 facing = player.transform.position - transform.position;

            // gets dot product of unit vectors
            float dot = Vector3.Dot(facing.normalized, transform.forward);

            // attempts to attack even if won't hit
            // functioning as a sound cue to help time strafing
            AudioSource.PlayClipAtPoint(attackSound, transform.position);

            if (dot >= 0.8f)
            {
                // attack
                playerStats.ChangePlayerHealth(-attackDamage);
            }

            hasSwung = true;
        }

        if (attackTime > attackDuration) // Resets attack abilities when done
        {
            hasSwung     = false;
            currentState = FSMStates.Chase;
            attackTime   = 0;
            anim.SetInteger("ActiveState", 1);
        }
    }
Exemplo n.º 25
0
    //executado quado esta patrulhando
    #region Idle
    private void Idle()
    {
        AranhaAnimator.SetBool("IsIdle", true);

        if (TakeDamage)
        {
            state = FSMStates.Damage;
        }

        if (Vector3.Distance(Target.transform.position, gameObject.transform.position) < Vision)
        {
            AranhaAnimator.SetBool("IsIdle", false);
            state = FSMStates.Walk;
        }
        TimeToNextPoint -= Time.deltaTime;
        if (TimeToNextPoint < 0)
        {
            currentWayPoint++;
            if (currentWayPoint >= waypoints.Length)
            {
                currentWayPoint = 0;
            }
            TimeToNextPoint = TimeTo;

            AranhaAnimator.SetBool("IsIdle", false);
            state = FSMStates.Patrol;
        }

        if (TakeDamage)
        {
            AranhaAnimator.SetBool("IsIdle", false);
            state = FSMStates.Damage;
        }
    }
Exemplo n.º 26
0
    public void AddFSMState(FSMStates fsmState)
    {
        // Check for Null reference before deleting
        if (fsmState == null)
        {
            Debug.LogError("FSM ERROR: Null reference is not allowed");
        }

        // First State inserted is also the Initial state
        //   the state the machine is in when the simulation begins
        if (fsmStates.Count == 0)
        {
            fsmStates.Add(fsmState);
            currentState   = fsmState;
            currentStateID = fsmState.ID;
            return;
        }

        // Add the state to the List if it´s not inside it
        foreach (FSMStates state in fsmStates)
        {
            if (state.ID == fsmState.ID)
            {
                Debug.LogError("FSM ERROR: Trying to add a state that was already inside the list");
                return;
            }
        }

        //If no state in the current then add the state to the list
        fsmStates.Add(fsmState);
    }
Exemplo n.º 27
0
    //estado de patrulha da Aranha
    #region Patrol
    private void Patrol()
    {
        AranhaAnimator.SetBool("IsWalk", true);

        if (TakeDamage)
        {
            state = FSMStates.Damage;
        }


        Vector3 dir = waypoints[currentWayPoint].position - transform.position;

        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), Time.deltaTime * RotationSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

        if (dir.sqrMagnitude <= 1)
        {
            AranhaAnimator.SetBool("IsWalk", false);
            state = FSMStates.Idle;
        }
        else
        {
            rb.MovePosition(transform.position + transform.forward * Time.deltaTime * MoveSpeed);
        }

        if (Distace < Vision)
        {
            state = FSMStates.Walk;
        }
        if (TakeDamage)
        {
            AranhaAnimator.SetBool("IsWalk", false);
            state = FSMStates.Damage;
        }
    }
Exemplo n.º 28
0
    private void ChaseState()
    {
        // Check if target is close enough to shoot or fire
        //   or if target is too far way, then return to Waypoints
        if (dir.magnitude > distanceToStopChasing)
        {
            state = FSMStates.Waypoints;
            return;
        }
        else if (dir.magnitude <= distanceToAttack)
        {
            timer       = 0;
            rb.velocity = Vector3.zero;
            // Get a random number to choose one of the attacks
            float randomNumber = UnityEngine.Random.Range(0F, 10F);
            if (randomNumber > chanceToFire)
            {
                state = FSMStates.Firing;
                flame.SetActive(true);
            }
            else
            {
                state          = FSMStates.Shooting;
                numberOfShoots = 0;
            }
            return;
        }

        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), Time.deltaTime * rotSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
        rb.MovePosition(transform.position + transform.forward * speed * Time.deltaTime);
    }
Exemplo n.º 29
0
    //estado de ataque fraco da Aranha
    #region ATK1
    private void ATK1()
    {
        AranhaAnimator.SetBool("IsIdle", true);

        if (TakeDamage)
        {
            state = FSMStates.Damage;
        }

        //rotaciona o Npc apontando para o alvo
        transform.rotation    = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Target.transform.position - myTransform.position), Time.deltaTime * RotationSpeed);
        transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

        TimerAtk += Time.deltaTime;
        if (Distace <= EnemyDist && TimerAtk >= CooldownAtk)
        {
            AranhaAnimator.SetBool("IsIdle", false);
            AranhaAnimator.SetTrigger("ATK");
            state    = FSMStates.ATK2;
            TimerAtk = 0;
        }
        if (Distace > EnemyDist)
        {
            AranhaAnimator.SetBool("IsIdle", false);
            state = FSMStates.Patrol;
        }
        if (TakeDamage)
        {
            AranhaAnimator.SetBool("IsIdle", false);
            state = FSMStates.Damage;
        }
    }
Exemplo n.º 30
0
    // Start is called before the first frame update
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;
        anim   = GetComponent <Animator>();

        state        = FSMStates.Sitting;
        doneStanding = false;
        spotted      = false;

        damageTaken = 0;

        particle0.SetActive(false);
        particle1.SetActive(false);

        src = Camera.main.GetComponent <AudioSource>();

        ragdoll = GetComponentsInChildren <Rigidbody>();
        foreach (Rigidbody rb in ragdoll)
        {
            rb.isKinematic = true;
        }

        startPos = transform.position;
        startRot = transform.rotation;

        LevelManager.onLevelReset += this.CheckPointReset;
    }
Exemplo n.º 31
0
 public FSMState(FSMStates type) {
     this.type = type;
 }