Book Image

Mastering Unity Scripting

By : Alan Thorn
Book Image

Mastering Unity Scripting

By: Alan Thorn

Overview of this book

Table of Contents (17 chapters)
Mastering Unity Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Camera shake


Now, here's an effect we can achieve with the Unity free version: camera shake! For fighting, shooting, and action games generally, a camera shake effect can be important. It conveys impact, danger, action, dynamism, and excitement—a form of kinetic feedback. It can, in fact, be used to stand in for lots of other animations too that simulate a pervasive motion and emotion where there really isn't any to be found elsewhere in the scene. To this extent, camera shakes can save us lots of work by creating an overarching animation, as shown here:

Camera shake effects

There are many ways to create camera shakes, but all of them involve fluctuation of the camera position between a minimum and maximum range using some kind of "randomness" function. Sometimes, the "randomness" is left raw, and sometimes, it's smoothened using the damping functionality to create a slower or more "flowing" shake. Refer to the following code sample 5-10 that can be attached to any camera to create a shake...