# Camera Shake

<figure><img src="https://3846168334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjeEdzvIH0d5vrHiguxu%2Fuploads%2FaLwishPskyPi5APXkztg%2Fcamerashakeexample.png?alt=media&#x26;token=81548b51-7b47-4e70-8d9e-2201e4f91d3d" alt=""><figcaption></figcaption></figure>

To start using Camera Shake you simply have to add the `CameraShakeController` to your camera.&#x20;

{% hint style="info" %}
It is recommended to add a parent to the Camera and have **all** movement logic in the parent instead. This will allow you to move the camera **and** apply shakes without it interferring with each other.
{% endhint %}

Now we can start creating a `Shake` object that stores all the configuration of a shake. Create a new `Shake` object by right-clicking the project and selecting `Create/Essentials/Camera/Shake`.

<figure><img src="https://3846168334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjeEdzvIH0d5vrHiguxu%2Fuploads%2FF7Ug5JM6bzDSskwx8wvb%2Fimage.png?alt=media&#x26;token=3fd22be5-b307-474f-8b55-4c924dbd21b8" alt=""><figcaption></figcaption></figure>

If you select the newly created `Shake` object you will see a couple of settings:

<figure><img src="https://3846168334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjeEdzvIH0d5vrHiguxu%2Fuploads%2F24Teq4B3BRcxr7oSArmw%2FScreenshot%202025-01-29%20152120.png?alt=media&#x26;token=b18b3c47-042a-4452-825f-f9649f2f3e0d" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can hover any property to see a tooltip explaining what it means and what it does.
{% endhint %}

Whenever you want to active the Camera Shake; you will need a reference to the `Shake` object. We can get this by simply exposing it in the inspector (alternatively, we can create a static reference letting us provide a string, or name of the desired shake and it will look it up and find it. This will be explained further later):

```csharp
public class TestShaker : MonoBehaviour
{
    public CameraShake shake;
    
    private void Start()
    {
        CameraShakeController.DoShake(shake);
    }
}
```

We can also see in the example above how we can start a shake: `CameraShakeController.DoShake(shake);`.

### Shake Configuration

To store a reference to a specific `Shake` object without exposing a property in the inspector for every script that triggers a camera shake, use a `Shake Config` object.

Like the pooling, we need to create a `Resources` folder anywhere in the project. Inside this project we should create a `Shake Config` by right-clicking under the folder and go to `Create/Essentials/Camera/Shake Config`.&#x20;

{% hint style="danger" %}
If you are creating your own `Shake Config` like above, you **must** remove the `Shake Config` in the `Camera Shake/Demo/Resources/Shake Config` or you can just use the **same** one as the demo.
{% endhint %}

{% hint style="warning" %}
There can always be exactly **one** `Shake Config` object in the project.
{% endhint %}

<figure><img src="https://3846168334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjeEdzvIH0d5vrHiguxu%2Fuploads%2FZbuzbQBD10PhWmYcNg6Y%2Fimage.png?alt=media&#x26;token=83d7d101-ed61-421f-bfad-51cd983bfa53" alt=""><figcaption></figcaption></figure>

Now by selecting the created `Shake Config`, we can add a new mapping. The `Name` defined what will be called when we trigger a shake and `Camera Shake` defined the `Shake` object when the name was triggered.

<figure><img src="https://3846168334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhjeEdzvIH0d5vrHiguxu%2Fuploads%2FFizTSqqG8Ot4Gd81NeIN%2Fimage.png?alt=media&#x26;token=76b681a2-359d-417d-a27f-5dcde4cec8ac" alt=""><figcaption></figcaption></figure>

Now we can omit the exposed inspector property when triggering a camera shake:

```csharp
public class TestShaker : MonoBehaviour
{
    private void Start()
    {
        CameraShakeController.DoShake("Shoot");
    }
}
```
