Example #1
0
    public static AudioCue PlaySound(AudioClip clip, Transform followTransform, AudioCue.CueSettings settings)
    {
        AudioCue cue = PlaySound(clip, followTransform.position, settings);

        cue.transform.parent = followTransform;
        return(cue);
    }
Example #2
0
    public void PlayFootstep(FootstepSurface.SurfaceType surfaceType, AudioCue.CueSettings soundSettings)
    {
        if (Mute)
        {
            return;
        }

#if UNITY_EDITOR || DEVELOPMENT_BUILD
        bool unsupportedSound = !(surfaceType == FootstepSurface.SurfaceType.UNKNOWN || _footstepAudioDictionary.ContainsKey(surfaceType));

        if (surfaceType == FootstepSurface.SurfaceType.UNKNOWN || unsupportedSound)
        {
            if (unsupportedSound)
            {
                Debug.LogWarningFormat("Attempting to play unsupported footstep sound {0}!", surfaceType.ToString());
            }
#else
        if (surfaceType == FootstepSurface.SurfaceType.UNKNOWN || !_footstepAudioDictionary.ContainsKey(surfaceType))
        {
#endif
            AudioManager.PlaySound(defaultFootstepSound, transform.position, soundSettings);
        }
        else
        {
            AudioManager.PlaySound(
                _footstepAudioDictionary[surfaceType].GetNext(),
                transform.position,
                soundSettings
                );
        }
    }
}
Example #3
0
    private void PlayerMovement()
    {
        if (!IsBeingControlled)
        {
            return;
        }
        // Planar Movement
        Vector3 moveCalc = (transform.forward * _moveInput.y + transform.right * _moveInput.x) * moveSpeed * (_sprintInput && _isGrounded && _moveInput.y > 0 ? sprintMultiplier : 1f);

        moveCalc = Vector3.ProjectOnPlane(moveCalc, _groundNormal);
        Debug.DrawRay(transform.position - Vector3.up * movementController.height * 0.5f, moveCalc, Color.yellow, 0.05f);
        moveCalc = Vector3.Lerp(new Vector3(movementController.velocity.x, 0f, movementController.velocity.z), moveCalc, _isGrounded ? moveGroundAccelLerp : moveAerialAccelLerp);
        Debug.DrawRay(transform.position - Vector3.up * movementController.height * 0.5f, moveCalc, Color.red, 0.05f);

        // Vertical Movement
        if (_isGrounded && _jumpInput)
        {
            // If can jump and trying to jump, jump! Applies no gravity this frame.
            moveCalc.y           = jumpForce;
            _currentYVelocityMax = jumpForce;

            // Play footstep audio at scaled volume to simulate pushing off the ground with both feet
            AudioCue.CueSettings cueSettings = footstepPlayer.FootStepSoundSettings;
            cueSettings.Volume *= jumpVolumeMultiplier;
            footstepPlayer.PlayFootstep(_groundSurfaceType, cueSettings);
            // Setting _isGrounded to false since we're no longer grounded
            _isGrounded = false;
        }
        else
        {
            //Footstep audio
            _distanceToNextFootstep -= moveCalc.magnitude * Time.deltaTime;
            if (_distanceToNextFootstep <= 0f && _isGrounded)
            {
                _distanceToNextFootstep = Util.RandomInRange(footstepStrideDistance);
                footstepPlayer.PlayFootstep(_groundSurfaceType);
            }

            // Keep the player moving at their current vertical speed.
            // Apply gravity, unless grounded (prevents slowly sliding down slopes)
            // Adding to preserve yVelocity from moveCalc being projected on ground plane.
            // using Min() to avoid issue where movementController y velocity spikes to go up steps.
            _currentYVelocityMax = Mathf.Max(0, Mathf.Min(movementController.velocity.y, _currentYVelocityMax));
            moveCalc.y          += Mathf.Min(movementController.velocity.y, _currentYVelocityMax);
            if (!_isGrounded)
            {
                moveCalc += Physics.gravity * Time.deltaTime;
            }
        }

        _jumpInput = false;

        movementController.Move(moveCalc * Time.deltaTime);
    }
Example #4
0
    public static AudioCue PlaySound(AudioClip clip, Vector3 location, AudioCue.CueSettings settings)
    {
        AudioCue cue = AudioCue.GetActiveCue();

        cue.transform.position = location;
        cue.Settings           = settings;
        cue.SetClip(clip);
        cue.Play();

        return(cue);
    }
Example #5
0
    private void OnPlayerBecomeGrounded()
    {
        // Play footstep sfx for landing on the ground
        _distanceToNextFootstep = Util.RandomInRange(footstepStrideDistance);
        AudioCue.CueSettings cueSettings = footstepPlayer.FootStepSoundSettings;
        cueSettings.Volume *= jumpVolumeMultiplier;
        footstepPlayer.PlayFootstep(_groundSurfaceType, cueSettings);

        // Apply some camera impulse to represent force of landing on the ground
        float strength = landingForceCurve.Evaluate(-movementController.velocity.y);

        if (strength > 0f)
        {
            MainCamera.Effects.ApplyImpulse(MainCamera.Camera.transform.position + Vector3.up, strength, strength * timeCurveScaler);
        }
        Debug.LogFormat("{0} => {1}", movementController.velocity.y, strength);
    }