How can access to noise module in runtime?

Hi,

I am triyng to add a temporal shake effect in to the “Free Look” camera like normal games when you receive damage the camera temporally shakes but i can’t find a access in the code for do that.
Noise module is exposed?

Regards.-

There are a couple of ways to do this:

  • With the noise module. Set a vibrating profile, and pulse it. See this thread: https://discussions.unity.com/t/672561/9 . The downside of this method is that you lose the ability to have handheld camera noise at the same time.
  • Since that thread was posted, the CinemachineExtension API became available. That would be the preferred approach. Here is a simplistic example, to shake the camera continuously. Modify it to make it do a pulse instead:
using UnityEngine;
using Cinemachine;

/// <summary>
/// An add-on module for Cinemachine to shake the camera
/// </summary>
[ExecuteInEditMode] [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
public class CameraShake : CinemachineExtension
{
    [Tooltip("Amplitude of the shake")]
    public float m_Range = 0.5f;

    protected override void PostPipelineStageCallback(
        CinemachineVirtualCameraBase vcam,
        CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    {
        if (stage == CinemachineCore.Stage.Body)
        {
            Vector3 shakeAmount = GetOffset();
            state.PositionCorrection += shakeAmount;
        }
    }

    Vector3 GetOffset()
    {
        return new Vector3(
            Random.Range(-m_Range, m_Range),
            Random.Range(-m_Range, m_Range),
            Random.Range(-m_Range, m_Range));
    }
}
2 Likes

Perfect! Thanks.