public override void Update(EnemyStateMachine enemy)
    {
        //If a target object exists, set the parent's destination to that object
        if (enemy.target != null && enemy.navMeshAgent != null)
        {
            //Set destination to that target
            enemy.destination = enemy.target.transform;

            //Tell the Nav Agent to move to the destination
            Vector3 destinationVector = enemy.destination.transform.position;
            enemy.navMeshAgent.SetDestination(destinationVector);
        }
        else
        {
            //If a target object does not exist, reset target threshold and return to idle state
            enemy.targetThreshold = 0;
            enemy.ChangeState(enemy.STATE_IDLE);
        }

        CheckTransitions(enemy);

        enemy.debugState = "CHASE";

        //Decrement timers
        enemy.attackTimer--;

        if (enemy.targetThreshold > 0)
        {
            enemy.targetThreshold--;
        }

        if (enemy.reactionTime > 0)
        {
            enemy.reactionTime--;
        }

        if (enemy.attackTimer == 0)
        {
            //Melee attack
            enemy.attackTimer = 50;
            if (CheckMeleeAttack(enemy))
            {
                enemy.ChangeState(enemy.STATE_MELEE_ATTACK);
            }

            //Ranged attack
            else if (CheckRangeAttack(enemy))
            {
                enemy.ChangeState(enemy.STATE_RANGE_ATTACK);
            }

            enemy.attackTimer = 50;
        }
    }
예제 #2
0
    public override void Update()
    {
        if (SearchPlayer())
        {
            _stateMachine.ChangeState(Global.AttackState);
        }

        _initTime += Time.deltaTime;
        if (_initTime >= _timeToChange)
        {
            _stateMachine.ChangeState(Global.IdleState);
        }
    }
    //Passive check to see if we need to change to another state
    private void CheckTransitions(EnemyStateMachine enemy)
    {
        //Transition back to StateIdle if you don't have a target
        if (enemy.target == null)
        {
            enemy.ChangeState(enemy.STATE_IDLE);
        }

        //Transition to StateDead is the enemy's health is 0 or less
        if (enemy.enemyHealth <= 0)
        {
            enemy.ChangeState(enemy.STATE_DEAD);
        }
    }
예제 #4
0
 public virtual void LogicUpdate()
 {
     if (IsDead())
     {
         _stateMachine.ChangeState(_enemyController.Dying);
     }
 }
예제 #5
0
 public override void Update()
 {
     _initTime += Time.deltaTime;
     if (_initTime >= _timeToChange)
     {
         _stateMachine.ChangeState(Global.PatrolState);
     }
 }
예제 #6
0
    public void FreezeEnemy(GameObject enemy, float defrostTime)
    {
        EnemyStateMachine enemyStateMachine = enemy.GetComponent <EnemyStateMachine>();

        enemyStateMachine.DefrostCurrentTimer = 0f;
        enemyStateMachine.DefrostTime         = defrostTime;
        enemyStateMachine.ChangeState(EnemyStateMachine.States.Frozen);
        // Debug.Log("PowerUp Frozen");
    }
예제 #7
0
    public void ParalyzeEnemy(GameObject enemy, float paralyzeTime)
    {
        EnemyStateMachine enemyStateMachine = enemy.GetComponent <EnemyStateMachine>();

        enemyStateMachine.ParalyzeHealCurrentTimer = 0;
        enemyStateMachine.ParalyzeHealTime         = paralyzeTime;
        enemyStateMachine.ChangeState(EnemyStateMachine.States.Paralyzed);
        // Debug.Log("PowerUp Paralyzed");
    }
예제 #8
0
    //Passive check to see if we need to change to another state
    public void CheckTransitions(EnemyStateMachine enemy)
    {
        if (player != null)
        {
            //SIGHT CHECK//
            //Check if the player is within a 180 degree view cone in front of the monster
            if (Vector3.Angle(enemy.transform.forward, player.transform.position - enemy.transform.position) < viewAngle)
            {
                RaycastHit hit;

                //Check if the monster has direct line of sight with the player
                if (Physics.Raycast(enemy.transform.position, (player.transform.position - enemy.transform.position), out hit))
                {
                    //Set the target to the player and begin chasing
                    if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Player"))
                    {
                        enemy.target = hit.collider.gameObject;
                        enemy.PlaySound(enemy.audioClips[Random.Range(0, 2)]);
                        enemy.ChangeState(enemy.STATE_CHASE);
                    }
                }
            }
            //DISTANCE CHECK//
            //Check if the player is within melee range of the monster
            if (Vector3.Distance(enemy.transform.position, player.transform.position) < enemy.meleeRange)
            {
                //Set the target to the player and begin chasing
                enemy.target = player;
                enemy.PlaySound(enemy.audioClips[Random.Range(0, 2)]);
                enemy.ChangeState(enemy.STATE_CHASE);
            }
        }

        //Transition to StateDead is the enemy's health is 0 or less
        if (enemy.enemyHealth <= 0)
        {
            enemy.ChangeState(enemy.STATE_DEAD);
        }
    }
    public override void Update(EnemyStateMachine enemy)
    {
        attackTime--;

        //Stop moving
        enemy.navMeshAgent.velocity = new Vector3(0, 0, 0);

        //Do attack
        if (attackTime == 0)
        {
            enemy.ChangeState(enemy.STATE_CHASE);
        }

        enemy.debugState = "ATTACK";
    }
예제 #10
0
    public override void Update()
    {
        _playerSpotted = SearchPlayer();
        float step = _speed * Time.deltaTime;

        _enemyRigidbody.position = Vector3.MoveTowards(_enemyRigidbody.position, _targetDestination, step);
        if (Vector3.Distance(_enemyRigidbody.position, _targetDestination) < 0.001f)
        {
            _targetDestination *= -1.0f;
        }
        _initTime += Time.deltaTime;
        if (_playerSpotted)
        {
            DashToPlayer();
        }
        else
        {
            _stateMachine.ChangeState(Global.IdleState);
        }
    }
예제 #11
0
 public virtual void Start()
 {
     StateMachine.ChangeState(new EnemyIdleState(this));
     NavMeshTow = GetComponent <NavMeshTowBehaviour>();
     Health     = MaxHealth;
 }
예제 #12
0
 private void Patrol()
 {
     stateMachine.ChangeState(EnemyState.PATROL);
 }
예제 #13
0
 void Start()
 {
     // set start state
     StateMachine.ChangeState(EnemyState.PatrolState);
 }