Shake


The Shake functionality allows you to shake the camera / screen or a gameobject, this can be used for a number of effects including giving more realism and impact to things like explosions or collisions.

Usage

Shake Camera

You can shake the camera by adding the Shake Camera component.

ShakeCamera

On this component you can specify the following values:

  • Cameras – A list of cameras to shake. If left empty cameras on the same gameobject as the component will be used, or if none are found the main camera.
  • Duration – The duration to shake the camera for.
  • Decay Start – The offset relative to duration after which to start decaying (slowing down) the movement in the range 0 to 1.
  • Range – The shake movement range from the origin. Set any dimension to 0 to stop movement along that axis.

The Shake Camera component is setup as a singleton both for ease of access and to maintain control. You can start the shake effect by calling;

  • ShakeCamera.Instance.Shake()
    This will shake the camera using the values set on the component.
  • ShakeCamera.Instance.Shake(float duration, Vector3 range, float decayStart)
    This will shake the camera using the passed values.

Note: for most effects small subtle values work best.

Scripting

There are some scripts and helper classes that you can use to help shake things including shaking any transform. The ShakeHelper class (in the FlipWebApps.BeautifulTransitions.Scripts.Shake namespace) contains methods to allow the following:

Shake any gameobject (transform)

To shake a transform call the ShakeHelper.Shake method. This takes the following parameters:

  • caller – A MonoBehaviour used to start the shake coroutine. If calling from your own component you can usually just pass ‘this’.
  • transform – The transform that you want to shake.
  • duration – The duration to shake the camera for.
  • range – The offset relative to duration after which to start decaying (slowing down) the movement in the range 0 to 1.
  • decayStart – The shake movement range from the origin. Set any dimension to 0 to stop movement along that axis.

At the current time only one active shake per transform is allowed.

Demo

Shake Camera Demo – A simple demonstration showing how you can shake the camera.

Additional Help

Please view the included demo’s under the \FlipWebApps\BeautifulTransitions\_Demo folder for examples and source code for implementing common scenarios.

If you need help or support then please visit our support forum, or let us know if you have any suggestions, feature requests or comments.