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

Cameras and curves


For cut-scenes, menu backgrounds, or simpler camera fly-throughs, you might just need the camera to travel roughly in a straight line that allows some curvature and fluctuation in speed as the camera moves using a smooth-in and smooth-out motion. This means that the camera picks up speed at the beginning and slowly drops in speed towards the end of the path. To achieve this, you can use a prescripted animation via Unity's animation editor, or you can use animation curves, which offer a high degree of flexibility and control over object transformations across time, as shown here:

Moving cameras with animation curves

To create a camera control script that allows you to control object speed and motion over time, including curved motion and smoothing or damping of speed, the following code sample 5-12 can be used:

//-----------------------------
 using UnityEngine;
 using System.Collections;
 //-----------------------------
 public class CameraMover : MonoBehaviour 
 {
    /...