# ObjectShake

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.

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2FYyeDdeuNeXQRDfzjPhlr%2Fimage.png?alt=media&#x26;token=6c5b4f65-79e8-4163-86b0-8290a057b9d6" alt=""><figcaption><p>Hierarchy best practises for ObjectShake</p></figcaption></figure>

<figure><img src="https://1613353771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fygjewtla1W7kzTTIpGWq%2Fuploads%2Fxk79G5MEQsQYOXWZNULN%2Fimage.png?alt=media&#x26;token=b8f28d5f-3703-41a8-ad64-57ce2fb2cb9a" alt=""><figcaption><p>Object Shake script in inspector</p></figcaption></figure>

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

{% code lineNumbers="true" %}

```csharp
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);
```

{% endcode %}
