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.-
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:
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));
}
}
Perfect! Thanks.