WEBVTT

00:00.040 --> 00:02.560
Let's make the camera follow.

00:02.560 --> 00:09.040
So if I go ahead and then hit this play button in the top in order to play our game, you will see my

00:09.240 --> 00:16.240
camera is not moving at all, even though we are moving our player GameObject left and right.

00:16.280 --> 00:17.560
Let me show you first.

00:17.720 --> 00:24.440
So let let's for a moment, let's, uh, wait a moment and we can see.

00:24.480 --> 00:29.440
As you can notice, the camera is not following, uh, our player at all.

00:30.160 --> 00:37.600
So we need to follow our player to do that for we will install Cinemachine Cinemachine camera in order

00:37.600 --> 00:39.720
to follow our player GameObject.

00:39.720 --> 00:41.440
So let's get out of play mode.

00:41.480 --> 00:44.080
Uh, to install Cinemachine, go to window.

00:44.080 --> 00:46.960
In the top you can see in the top bar window.

00:47.200 --> 00:52.880
Then move over to this package manager and in the left side you will see in project.

00:53.000 --> 00:55.800
In the left side you will see Unity Registry.

00:55.840 --> 01:00.180
Basically select the unity registry and over here you will see.

01:00.180 --> 01:03.740
So scroll down to the bottom and find over here cinemachine.

01:03.940 --> 01:06.740
And as you can notice right over I have.

01:06.860 --> 01:13.300
And if you not able to find it make sure you are in unity registry basically in the left.

01:13.700 --> 01:14.700
Choose that.

01:14.740 --> 01:21.820
Then search over here by typing cinemachine and it's gonna pop up and you will see an import button.

01:21.860 --> 01:23.780
Sorry, you will see an install button.

01:23.780 --> 01:29.020
So just click there and then Cinemachine just gonna import in your project.

01:29.020 --> 01:32.220
And once you are done and you are good to go.

01:32.260 --> 01:37.420
As you can notice, I already imported my cinemachine camera in my project.

01:37.420 --> 01:41.020
So let's cut this tab by now and let's create the camera.

01:41.020 --> 01:45.300
To create the camera, go over to hierarchy, right click or hit this plus icon.

01:45.540 --> 01:47.060
Then go over to Cinemachine.

01:47.060 --> 01:48.500
In the bottom you can see.

01:48.700 --> 01:52.300
Then target is camera and then click on this 2D camera.

01:52.660 --> 01:58.180
And now as soon as we added our Cinemachine camera we can see that.

01:58.550 --> 02:02.790
And if we select our main camera, we can see a.

02:03.950 --> 02:07.550
Basically, if I select my main camera, go over to Inspector.

02:07.670 --> 02:12.390
In the bottom you can see Cinemachine brain just added up to our main camera.

02:12.430 --> 02:18.630
As soon as we created this Cinemachine camera, why basically this Cinemachine brain component just

02:18.630 --> 02:24.510
gonna give instruction to our main camera, basically Cinemachine camera, just gonna give instruction

02:24.510 --> 02:25.870
to this main camera.

02:25.870 --> 02:28.670
So that's why this cinemachine brain just added up.

02:28.870 --> 02:32.310
So let's suppose we just want to move to the left direction.

02:32.310 --> 02:38.550
So this cinemachine camera just gonna give instruction instruction to this main camera in order to move

02:38.550 --> 02:40.790
this main camera to the left side.

02:40.790 --> 02:44.070
So that's why this cinemachine brain just added up right away.

02:44.270 --> 02:49.550
Once we created this cinemachine camera, it's gonna give instruction to our main camera.

02:49.790 --> 02:57.190
But if we just go ahead and then play our game, you will still able to notice our play.

02:57.370 --> 02:58.650
And basically main camera.

02:58.690 --> 03:01.850
Not gonna follow our player game object at all.

03:02.050 --> 03:02.490
Why?

03:02.530 --> 03:05.730
Basically, we need to make the tracking target.

03:06.130 --> 03:08.010
So if I just move left and right.

03:08.010 --> 03:11.770
As you can notice, main camera is not following at all.

03:11.890 --> 03:14.250
For that, we will get out of play mode for it.

03:14.290 --> 03:17.370
We need to select our Cinemachine camera in the hierarchy.

03:17.410 --> 03:21.370
Then go over to Inspector, then Cinemachine camera component.

03:21.370 --> 03:26.890
And over here we can see tracking target slot and it says None transform.

03:26.970 --> 03:29.250
Basically we need to drag the GameObject.

03:29.410 --> 03:33.690
Which GameObject we just really want our main camera to follow.

03:33.930 --> 03:37.130
So in our case we're gonna follow our player GameObject.

03:37.130 --> 03:42.610
So that's why we will select our player Game object from hierarchy and drag it over to that tracking

03:42.650 --> 03:43.650
target slot.

03:43.650 --> 03:52.130
And as soon as we drag it now our main camera just gets his position to our player a game object.

03:52.130 --> 03:57.180
And if we just go ahead and then click on this play button in the top, you will see.

03:57.220 --> 04:03.940
By now, the camera is just gonna follow our player wherever player goes to the left or right direction.

04:03.940 --> 04:05.180
Even we jumping.

04:05.900 --> 04:10.740
So if I just play my game, if we try to move left and right.

04:10.780 --> 04:13.540
As you can notice, main camera is now following.

04:13.580 --> 04:19.900
And if we jump in the way we can see indeed our main camera is following our player game object in the

04:19.900 --> 04:21.540
y axis as well.

04:21.660 --> 04:28.100
Let's suppose you want some area you don't want to move or don't want to move your camera.

04:28.540 --> 04:34.660
But if you surpass this position and you want your main camera to follow, then you can just do that

04:34.660 --> 04:35.060
for it.

04:35.100 --> 04:38.220
What you have to do, you need to move over to Inspector.

04:38.220 --> 04:43.700
Firstly, select your cinemachine camera in the hierarchy, then go over to Inspector, then Cinemachine

04:43.700 --> 04:47.220
camera component, then Cinemachine position component.

04:47.220 --> 04:48.580
In the bottom you can see.

04:48.580 --> 04:54.140
So just go there and then click on this date zone and click on this date zone.

04:54.140 --> 05:00.680
And as soon as we check we can see an area just just became in our game view.

05:00.720 --> 05:01.920
We can notice that.

05:01.920 --> 05:09.040
So this will be the area that if we just move around in in this area, in this area then main camera

05:09.040 --> 05:10.880
not gonna follow at all.

05:10.880 --> 05:17.600
But if we surpass this area then our main camera will start following our player game object.

05:17.640 --> 05:18.680
Let me show you.

05:18.680 --> 05:24.480
So as you can notice that if we try to move left and right, we are not able to notice our main camera

05:24.480 --> 05:25.240
to follow.

05:25.240 --> 05:32.640
But once we surpass this area, basically this dead zone we can see the main camera is not is basically

05:32.640 --> 05:34.120
following our player.

05:34.320 --> 05:38.640
So this is the dead zone and you can just play around with this number.

05:38.640 --> 05:41.080
So I'm gonna make a little bit small.

05:41.120 --> 05:42.800
I want a small area.

05:43.040 --> 05:50.600
And if I just surpass that area then I want my camera to follow this player game object right after

05:50.600 --> 05:52.040
this player game object.

05:52.040 --> 05:58.370
So to do that, we will go over to Cinemachine position component component right over here.

05:58.850 --> 06:01.530
Firstly, select your Cinemachine camera in the hierarchy.

06:01.530 --> 06:03.170
Then go over to Inspector.

06:03.170 --> 06:10.210
In the bottom you can see that component which is uh which says Cinemachine position component.

06:10.210 --> 06:11.770
And we can right click on it.

06:11.770 --> 06:15.930
And if we click on this properties it's going to pop up with an tab.

06:15.930 --> 06:18.170
As you can notice right over here.

06:18.170 --> 06:20.530
And you can just play around with this value.

06:20.890 --> 06:25.450
And let's say I want a little bit small this area which is the death zone.

06:25.450 --> 06:29.050
So I'm going to choose something like point instead of point two.

06:29.250 --> 06:32.170
And we can see the area is now little bit.

06:32.170 --> 06:36.010
But so in this area we can just move left and right.

06:36.010 --> 06:38.890
And when camera is not following at all.

06:38.890 --> 06:46.810
But once we surpass this area, camera just started following our player in the x axis basically horizontally,

06:47.090 --> 06:48.290
as you can notice.

06:48.450 --> 06:53.610
And if you want to do with in the Y as well, you can just increase the value in the Y.

06:53.790 --> 06:59.990
I'm not gonna do a doo doo at all in the y axis, so I can just set it to zero.

07:00.390 --> 07:02.350
So it's not going to do at all.

07:02.550 --> 07:07.430
And we can play around with the is basically this is a screen position.

07:07.790 --> 07:11.390
If we set it to zero let's suppose you want to increase this value.

07:11.390 --> 07:12.390
As you can see.

07:12.790 --> 07:14.110
Are we gonna be here.

07:14.110 --> 07:15.950
You can just play around with this.

07:15.990 --> 07:17.510
I'm gonna set it to zero.

07:17.710 --> 07:23.430
And let's suppose you just want to move your camera a little bit up direction or vertically.

07:23.430 --> 07:25.870
Then you can increase this y value.

07:25.870 --> 07:28.510
And we can see as soon as we increasing.

07:28.830 --> 07:29.390
Sorry.

07:29.590 --> 07:31.790
Not increasing basically decreasing.

07:31.830 --> 07:37.270
We can see the main camera in the y axis is getting a little bit up.

07:37.590 --> 07:40.030
And you can just play around with that number.

07:40.430 --> 07:44.870
And since I one sorry increasing or decreasing I don't know.

07:46.710 --> 07:47.110
Sorry.

07:47.150 --> 07:48.990
We need to play around with this value.

07:49.310 --> 07:51.950
So we gonna set back to zero.

07:51.950 --> 07:57.520
So just play around with this, and you're gonna get all of the things you can make the target offset.

07:57.560 --> 07:59.360
We can see right over here.

07:59.520 --> 08:04.440
We can do it like this, and we can play around with the Y as well.

08:04.800 --> 08:06.440
And I'm going to set back to zero.

08:07.000 --> 08:10.880
So just play around with this number and you're gonna get all of these things.

08:11.160 --> 08:13.440
And make sure you just right click on that.

08:13.560 --> 08:18.480
Right click on Cinemachine a Cinemachine position composer component.

08:18.800 --> 08:21.440
Sorry Cinemachine Position Composer component.

08:21.440 --> 08:24.360
Right click on it and then copy component.

08:24.400 --> 08:29.760
And because we're doing inside a play mode, so it's not gonna save at all.

08:29.800 --> 08:32.480
So once we get outside of play mode.

08:32.480 --> 08:34.560
So that's why we need to paste those values.

08:34.560 --> 08:38.520
Or we need to remember this since I don't want to remember.

08:38.520 --> 08:44.080
So that's why I'm gonna right click on that component which is Cinemachine position composer component.

08:44.080 --> 08:44.400
Right.

08:44.400 --> 08:47.840
Let's right click on it and then click on this copy component.

08:47.840 --> 08:50.160
So all of the properties we just copied.

08:50.160 --> 08:51.760
And we can just cut this tab.

08:51.780 --> 08:56.900
or you can simply move over to your inspector, then go over to bottom Cinemachine.

08:56.980 --> 08:59.420
Cinemachine position Composer component.

08:59.420 --> 09:01.260
Right click on it and then copy.

09:01.300 --> 09:02.940
Click on this copy component.

09:02.940 --> 09:05.100
So it's going to copy all of the component.

09:05.100 --> 09:10.620
And if we get out of play mode we just getting back our value to default.

09:10.620 --> 09:16.740
So what we can do by now we can just right click on that component and then right click on that component.

09:16.740 --> 09:20.940
And then we can just click on this paste component values.

09:20.940 --> 09:28.620
And as soon as we paste we can see the dead zone that zone in the X or horizontally which are which

09:28.620 --> 09:30.940
we set inside play mode point one.

09:30.940 --> 09:33.460
And now it gets back to point one.

09:33.460 --> 09:36.300
Once we just paste our component values.

09:36.300 --> 09:40.060
So you can just play around with this and you're gonna get all of the things.

09:40.100 --> 09:44.700
Let's suppose you just want to just want your main camera to zoom in.

09:45.060 --> 09:49.180
Then what you need to do, you need to go over to this cinemachine camera component.

09:49.180 --> 09:54.150
And then you need to move over to this lens and you can just play around with this value.

09:54.150 --> 09:56.830
So if I increase orthographic size.

09:56.830 --> 09:59.670
So make sure you select your cinemachine camera first.

09:59.670 --> 10:05.110
Then go over to Inspector Cinemachine camera component and then move over to this lens section.

10:05.110 --> 10:11.350
And if you just increase that value something like ten, we can see the camera just zooming out.

10:11.350 --> 10:13.790
And let's suppose you want to zoom in.

10:13.830 --> 10:17.950
Then you can just decrease this lens value to something like five.

10:18.190 --> 10:20.830
And if we set it to five it just zoomed in.

10:20.830 --> 10:25.270
So I'm going to set it to seven something like that amount like that.

10:25.750 --> 10:32.750
And if I select my different game object in the hierarchy now we can see that it's gone.

10:32.750 --> 10:36.230
Basically the outlines the lines is gone.

10:36.270 --> 10:43.790
Because as soon as we choose our cinemachine we can see this line, as you can notice right over here.

10:44.470 --> 10:51.170
But if we select different game object in the hierarchy, we can see those lines just a fade just goes

10:51.210 --> 10:51.650
out.

10:51.850 --> 10:57.290
And if we just go ahead and then click on this play button in the top to play our game, we will see

10:57.290 --> 10:58.050
our main camera.

10:58.090 --> 11:03.810
Just gonna follow our player game object in the direction the player is going, and play around with

11:03.810 --> 11:08.450
those values like the death zone in the X and Y, and you're gonna get.

11:08.490 --> 11:10.730
As you can see, this is our death zone.

11:10.730 --> 11:17.570
But once we surpass this dead zone, the camera started following our player in the Y as well as in

11:17.570 --> 11:19.530
the X axis.

11:19.530 --> 11:25.810
And we can play around with the offset if you want your main camera a little bit up direction in the

11:25.810 --> 11:32.170
Y, then you can just get out of play mode, then select your Cinemachine camera, then go over to Inspector,

11:32.210 --> 11:35.770
then Cinemachine Position Composer component in the bottom.

11:36.010 --> 11:44.210
Then go over to composition composition right over here and increase the value or decrease the value

11:44.210 --> 11:45.010
in the Y.

11:45.050 --> 11:46.490
And you're gonna get that.

11:46.490 --> 11:48.250
So basically that is the thing.

11:48.250 --> 11:53.460
So I'm going to set it to something like point one, point one, something like that.

11:53.460 --> 11:56.060
Or we can just make this value small.

11:56.060 --> 12:01.700
So it's going to be in the up direction, I guess we can play around and we're going to get that.

12:01.700 --> 12:03.780
So you can just play around like this.

12:03.780 --> 12:05.700
You can just increase or decrease.

12:05.740 --> 12:12.980
It's basically after you if you just want your main camera in the up a little bit in the Y direction

12:12.980 --> 12:15.220
or in the up direction a little bit.

12:15.300 --> 12:17.020
So basically that is the thing.

12:17.020 --> 12:23.540
So I hope you get the idea that how you can install your cinemachine, uh cinemachine camera and how

12:23.540 --> 12:28.820
you can import in your project and play around with these values and you're gonna get that.

12:28.940 --> 12:34.900
And also we need to drag our backgrounds, we need to make parallax effect and all of those things.

12:34.900 --> 12:38.500
Also, we need to make the camera shake effect as well.

12:38.860 --> 12:40.860
So we need to do those things.

12:40.980 --> 12:45.460
And we're going to do it in the next, uh, in the later lectures.

12:45.460 --> 12:48.580
So I hope you get the idea that how you can do this.
