Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In mathematics, sine is a trigonometric function of an angle. It can be used to smoothly oscillate a value, such as the camera's position.
Resources
 Cameras in Unity  Project Files  This is a zip file that contains the Unity project for this course. Download the file, unzip it, and then in your file browser (Finder on OS X and Exporer on Windows) navigate to Cameras in Unity > Assets > _Scenes. Finally, choose the scene you'd like to open.

0:00
[MUSIC]

0:04
So far we've created one camera that captures the game play but

0:08
it would be more interesting if the camera were moving very slightly.

0:13
When a camera remains completely still like the one we've created,

0:17
it can draw too much attention to the artificial nature of the scene,

0:22
which can take the player out of the experience.

0:25
Instead of making the camera static,

0:27
we can add some subtle movement to help see the believability of the scene.

0:33
There are many ways we could approach this problem.

0:36
For example we could use the lerp method

0:40
to move a camera between two points or we could use animation curves.

0:45
However, for this scene,

0:47
we want to create several cameras that smoothly oscillate between two points.

0:52
This type of movement maps very closely to a sine wave.

0:57
In mathematics, sine is a trigonometric function of an angle.

1:02
If you haven't taken a trigonometry class or if you slept through it, don't worry.

1:07
Because we don't actually need a lot of math, for the math we do need, I'll walk

1:13
through it step by step, and then we'll apply it to our cameras and our code.

1:19
[NOISE] A sine wave is typically visualized as a graph that looks

1:24
like this.

1:25
It oscillates back and forth between two values for an infinite amount of time.

1:32
At any given time, we can sample a value from the graph and

1:36
then apply it to one of the transform values on a game object.

1:41
For example, we could make a camera oscillate between a z value of

1:46
positive two and negative two, so that it moves forward and back.

1:52
The distance that a game object should move can be calculated

1:56
using the formula distance equals the sine of theta times amplitude.

2:02
Theta is time divided by a time period.

2:06
Or just period for short.

2:09
So the formula can be expanded to look like this.

2:14
Manipulating the period and

2:16
amplitude variables will have different effects on the resulting distance.

2:21
If the period is increased each wave will be stretched over a larger time period,

2:27
which means that the camera might take longer to go from point A to point B, and

2:32
then back again.

2:33
If the period is decreased, the opposite will occur.

2:37
A camera will move quickly back and forth.

2:41
If the amplitude is increased, the values of top and

2:45
bottom of the graph will loop further away from zero.

2:48
For example, if the amplitude changes from a value of two to

2:54
a value of four, then instead of a camera moving between to a negative two,

2:58
it will now move between four and negative four.

3:02
Keep in mind that if the period is not also adjusted,

3:06
this could have the appearance of a camera moving faster.

3:10
This was just a brief overview of the math of sine waves and

3:14
how they can be used to animate game objects.

3:17
If you didn't understand everything don't worry.

3:20
We'll get some practice with these concepts and

3:23
if you still like you need to review them you can always go back.
You need to sign up for Treehouse in order to download course files.
Sign up