🧊ObjectShake

Used to make object shake effect

Is used by CameraFollower custom camera system to make camera shake effect.

How to use

Best practises is to make empty parent with child, where child will have ObjectShake script. It means that when shake will be active -> child object will move and you still can move parent (base) object.

Hierarchy best practises for ObjectShake
Object Shake script in inspector

In ObjectShake script you need to reference to Transform that will shake by API calls. Also you can setup Shake In/Out curves <- this is how shake effect will appear and disappear (linear, sinInOut and etc).

Then when you need -> call API DoShake() method to trigger object shake effect.

API

public Transform ObjShakeTransform;

/// <summary>
/// Set it to true to ignore DoShake() Calls
/// </summary>
public bool IgnoreShake;


/// <summary>
/// Short func version of shake effect
/// </summary>
public void DoFastShake(float shakeAmount, float frequency = 25f, 
        bool overrideCurrent = true, bool timeDependent = true);


/// <summary>
/// Starts continious shake, note if you will run new shake then it will continue after new one finished
/// Use StopContiniousShake to stop it
/// </summary>
public void DoContiniousShake(ShakeSnapshoot snapshoot);
public void DoContiniousShake(float shakeAmount, float frequency = 25f, float attackTime = 0.2f,
                              float releaseTime = 0.5f, bool timeDependent = true, float seed = -1);


/// <summary>
/// Stops continious shake, has no effects if there is no continious shake
/// </summary>
public void StopContiniousShake(bool immediately = false);

/// <summary>
/// Turns on shake effect for a while
/// </summary>
/// <param name="shakeAmount">shake effect max distance from original pos</param>
/// <param name="attackTime">shake effect go in time</param>
/// <param name="decayTime">shake effect duration after go in time</param>
/// <param name="releaseTime">shake effect go out time</param>
/// <param name="timeDependent">if false - will be used unscaled delta time</param>
/// <param name="overrideCurrent">if false - shake will be ignored if it's already enabled</param>
public void DoShake(float shakeAmount, float frequency = 25f, float attackTime = 0.2f, 
    float decayTime = 1f, float releaseTime = 0.5f, 
    bool timeDependent = true, bool overrideCurrent = true, float seed = -1);
    
public void DoShake(ShakeSnapshoot shakeSnapshoot, int seed = -1)

/// <summary>
/// Immediately stops shake effect
/// </summary>
public void StopShake();

/// <summary>
/// Stops active shake effect with it's release time
/// </summary>
public void StopShakeWithReleaseTime();

/// <summary>
/// Use it if you want to override current easings of in and out shake phases
/// </summary>
/// <param name="inShakeCurve">will be ignored if null</param>
/// <param name="outShakeCurve">will be ignored if null</param>
public void SetShakeInOutCurves(AnimationCurve inShakeCurve, AnimationCurve outShakeCurve);

Last updated