Camera Shake
This package aims to simplify how Camera Shake is implemented and used.
Last updated
This package aims to simplify how Camera Shake is implemented and used.
Last updated
To start using Camera Shake you simply have to add the CameraShakeController
to your camera.
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.
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
.
If you select the newly created Shake
object you will see a couple of settings:
You can hover any property to see a tooltip explaining what it means and what it does.
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):
We can also see in the example above how we can start a shake: CameraShakeController.DoShake(shake);
.
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
.
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.
There can always be exactly one Shake Config
object in the project.
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.
Now we can omit the exposed inspector property when triggering a camera shake: