void ITurrets.Tick()
    {
        _timePass += 1 * Time.deltaTime;

        if (_mag <= 0)
        {
            _self.ChangeState(E_Turret.RELOADING);
        }

        if (_player != null)
        {
            Quaternion lookTarget = Quaternion.LookRotation((_player.CameraController.transform.position - _transform.position).normalized);

            _currentRotSpeed = Mathf.Lerp(_currentRotSpeed, (float)_self.RotationSpeed, (float)_rotSmooth * Time.deltaTime);

            _transform.rotation = Quaternion.Slerp(_transform.rotation, lookTarget, _currentRotSpeed * Time.deltaTime);
        }

        if (_timePass > _rateOfFire)
        {
            _self.Shoot(_bullet, _shootingPos, Quaternion.identity);
            _timePass = 0;
            _mag--;
        }
    }
예제 #2
0
    void ITurrets.Tick()
    {
        _timePass += 1f * Time.deltaTime;

        if (_timePass > _reloadSpeed)
        {
            _mag++;
            _timePass = 0;
        }

        if (_mag >= _self.MaxMagazine)
        {
            _self.ChangeState(E_Turret.SEARCHING);
        }
    }
예제 #3
0
    void ITurrets.Tick()
    {
        _player = PlayerManager.Instance.Player;

        _currentRotSpeed = Mathf.Lerp(_currentRotSpeed, (float)_self.RotationSpeed, (float)_rotSmooth * Time.deltaTime);

        float angle = Mathf.Abs(Vector3.Angle(_player.transform.position - _self.transform.position + Vector3.up, _self.transform.forward));

        if (angle < _viewField)
        {
            RaycastHit hit;

            bool isTrue = Physics.Raycast(_self.transform.position, _player.transform.position + Vector3.up - _self.transform.position, out hit, (float)_viewDistance, _self.Target);

            if (isTrue == true)
            {
                _player = hit.transform.GetComponent <PlayerController>();

                if (_player != null)
                {
                    _self.ChangeState(E_Turret.SHOOTING);
                    _self.Player = _player;
                }
            }
        }

        if (_isAtStartingRot == false)
        {
            Vector3 startEulerAngle     = new Vector3(_self.transform.eulerAngles.x, _startEulerAngle.y, _self.transform.eulerAngles.z);
            float   distFormOriginalRot = Vector3.Distance(_self.transform.eulerAngles, startEulerAngle);

            _self.transform.eulerAngles = Vector3.Lerp(_self.transform.eulerAngles, startEulerAngle, _currentRotSpeed * Time.deltaTime);

            if (distFormOriginalRot < 0.1f)
            {
                _self.transform.eulerAngles = _startEulerAngle;
                _currentRotSpeed            = 0;
                _timePass        = 0;
                _isAtStartingRot = true;
            }
        }
        else
        {
            LookAround();
        }
    }