Ejemplo n.º 1
0
    void CarryOutEnemiesDetection()
    {
        if (Time.time > _nextCheck)
        {
            _nextCheck = Time.time + _checkRate;

            Collider[] colliders = Physics.OverlapSphere(_myTransform.position, _detectRadius, _sightLayer);

            if (colliders.Length > 0)
            {
                bool targetExist = false;
                foreach (Collider potentialTargetCollider in colliders) //Breaking the for loop because if we got the near one no need to attack the far one right now.
                {
                    if (CanPotentialTargetBeSeen(potentialTargetCollider.transform))
                    {
                        targetExist    = true;
                        _retrysCounter = 0;
                        break;
                    }
                    else
                    {
                        _retrysCounter++;
                    }
                }
                if (_isEnemySeen && !targetExist && _retrysCounter > _retrysToSee)
                {
                    _isEnemySeen = false;
                    _botMaster.CallEventEnemyLostTarget(_lastSeenPlace);
                }
            }
            else
            {
                if (_isEnemySeen)
                {
                    _isEnemySeen = false;
                    _botMaster.CallEventEnemyLostTarget(_lastSeenPlace);
                }
                else if (_botMaster.isNavPaused)
                {
                    _botMaster.CallEventEnemyRestartNavTrip(0.05f);
                }
            }
        }
    }
Ejemplo n.º 2
0
    void TryToAttack()
    {
        Transform targetTransform = null;

        if (_seenTargets.Count > 0)
        {
            if (Time.time > _nextSwitchEnemy)
            {
                _nextSwitchEnemy   = Time.time + _switchEnemyRate;
                _currentEnemyIndex = Random.Range(0, _seenTargets.Count);
            }
            if (_currentEnemyIndex < _seenTargets.Count)
            {
                if (_seenTargets.Count > 1 && _seenTargets.ElementAt(_currentEnemyIndex).Key.gameObject.layer == GameConstants.ObjectiveLayer)
                {
                    if (_seenTargets.Count == 2)
                    {
                        _currentEnemyIndex = 1 - _currentEnemyIndex; //This trick to get the other element.
                    }
                    else
                    {
                        _currentEnemyIndex = Random.Range(0, _seenTargets.Count); //It will give a second chance for randomization behaviour.
                    }
                }
                _nextAttack = Time.time + _attackRate;
                if (Vector3.Distance(_myTransform.position, _seenTargets.ElementAt(_currentEnemyIndex).Key.position) <= _attackRange)
                {
                    _isFiring = true;
                    Vector3 lookAtVector = new Vector3(_seenTargets.ElementAt(_currentEnemyIndex).Key.position.x, _myTransform.position.y, _seenTargets.ElementAt(_currentEnemyIndex).Key.position.z);
                    _myTransform.LookAt(lookAtVector);
                    targetTransform = _seenTargets.ElementAt(_currentEnemyIndex).Key;
                    LookAtTarget(transform, targetTransform.position);
                    AimOnTarget(targetTransform);
                    if (_botMedic.enabled)
                    {
                        Utils.LogError("Looking At   " + targetTransform.name);
                    }
                    _botMaster.CallEventEnemyAttack(true);
                }
                else if (_isFiring && _seenTargets.Count > 0)
                {
                    _botMaster.CallEventEnemyLostTarget(_seenTargets.ElementAt(_currentEnemyIndex).Key);
                }
            }
        }
    }
Ejemplo n.º 3
0
    void TryToHeal()
    {
        Transform targetTransform = null;

        if (_seenTargets.Count > 0)
        {
            if (_shouldSwitchEnemy)
            {
                _shouldSwitchEnemy = false;
                _currentAllyIndex  = Random.Range(0, _seenTargets.Count);
            }
            if (_currentAllyIndex < _seenTargets.Count)
            {
                _nextAttack = Time.time + _attackRate;
                if (Vector3.Distance(transform.position, _seenTargets.ElementAt(_currentAllyIndex).Key.position) <= _attackRange)
                {
                    _isFiring = true;
                    Vector3 lookAtVector = new Vector3(_seenTargets.ElementAt(_currentAllyIndex).Key.position.x, transform.position.y, _seenTargets.ElementAt(_currentAllyIndex).Key.position.z);
                    targetTransform = _seenTargets.ElementAt(_currentAllyIndex).Key;
                    _botMaster.CallEventEnemyAttack(true);
                }
                else if (_isFiring && _seenTargets.Count > 0)
                {
                    _botMaster.CallEventEnemyLostTarget(_seenTargets.ElementAt(_currentAllyIndex).Key);
                }
            }
        }

        if (targetTransform == null)
        {
            LookAtTarget(transform, null);
            AimOnTarget(null);
        }
        else
        {
            LookAtTarget(transform, targetTransform.position);
            AimOnTarget(targetTransform);
        }
    }