コード例 #1
0
        /// <summary>
        /// Every frame, we check if we're crouched and if we still should be
        /// </summary>
        public override void ProcessAbility()
        {
            base.ProcessAbility();

            // if we don't have a model, we do nothing and exit
            if (_model == null)
            {
                return;
            }

            _currentAngle = DetermineAngle();

            if (_characterGravity != null)
            {
                _currentAngle += _characterGravity.GravityAngle;
            }

            // we determine the new rotation
            _newRotation = Quaternion.Euler(_currentAngle * Vector3.forward);

            // if we want instant rotation, we apply it directly
            if (CharacterRotationSpeed == 0)
            {
                _model.transform.rotation = _newRotation;
            }
            // otherwise we lerp the rotation
            else
            {
                _model.transform.rotation = Quaternion.Lerp(_model.transform.rotation, _newRotation, CharacterRotationSpeed * Time.deltaTime);
            }

            if ((_weaponAim == null) && (_handleWeapon != null))
            {
                if (_handleWeapon.CurrentWeapon != null)
                {
                    _weaponAim = _handleWeapon.CurrentWeapon.GetComponent <WeaponAim>();
                }
            }

            // if we're supposed to also rotate the weapon
            if (RotateWeapon && (_weaponAim != null))
            {
                if (_characterGravity != null)
                {
                    _currentAngle -= _characterGravity.GravityAngle;
                }
                _weaponAim.ResetAdditionalAngle();
                _weaponAim.AddAdditionalAngle(_currentAngle);
            }
        }
コード例 #2
0
        /// <summary>
        /// Every frame, we check if we're crouched and if we still should be
        /// </summary>
        public override void ProcessAbility()
        {
            base.ProcessAbility();

            // if we don't have a model, we do nothing and exit
            if (_model == null)
            {
                return;
            }

            // we get the current angle between the character and the slope it's on from the controller
            _currentAngle = _controller.State.BelowSlopeAngle;
            // if we're in the air and if we should be resetting the angle, we reset it
            if ((!_controller.State.IsGrounded) && ResetAngleInTheAir)
            {
                _currentAngle = 0;
            }

            // we clamp our angle
            _currentAngle = Mathf.Clamp(_currentAngle, MinimumAllowedAngle, MaximumAllowedAngle);

            if (_characterGravity != null)
            {
                _currentAngle += _characterGravity.GravityAngle;
            }

            // we determine the new rotation
            _newRotation = Quaternion.Euler(_currentAngle * Vector3.forward);

            // if we want instant rotation, we apply it directly
            if (CharacterRotationSpeed == 0)
            {
                _model.transform.rotation = _newRotation;
            }
            // otherwise we lerp the rotation
            else
            {
                _model.transform.rotation = Quaternion.Lerp(_model.transform.rotation, _newRotation, CharacterRotationSpeed * Time.deltaTime);
            }

            // if we're supposed to also rotate the weapon
            if (RotateWeapon && (_weaponAim != null))
            {
                if (_characterGravity != null)
                {
                    _currentAngle -= _characterGravity.GravityAngle;
                }
                _weaponAim.AddAdditionalAngle(_currentAngle);
            }
        }