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 gameplay, 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 sell 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 to move a camera between two points,

0:42
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,

1:07
don't worry because we don't actually need a lot of math.

1:10
For the math we do need, I'll walk through it step by step and

1:15
then we'll apply it to our camera's Android code.

1:19
A sine wave is typically visualized as a graph that looks 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 transformed values on a game object.

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

1:47
2 so that it moves forward and back.

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

1:56
utilizing the formula distance = sin(theta) x amplitude.

2:02
Theta is time divided by a time period, 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 at the top and

2:45
bottom of the graph will move further away from 0.

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

2:54
a value of 4, then instead of the camera moving between 2 and 2,

2:58
it will now move between 4 and 4.

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.

3:22
And if you still feel 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