WEBVTT

00:00.000 --> 00:00.420
Hello, guys.

00:00.420 --> 00:01.350
Welcome to the video.

00:01.350 --> 00:03.990
Uh, in this section, we're going to work on camera.

00:03.990 --> 00:09.030
I just want to explain how camera works, how you can use the camera, how you can set up dynamic camera.

00:09.030 --> 00:11.850
Also, I want to show you a couple of tricks to improve game feel.

00:11.850 --> 00:15.360
And in general, I think it's a good knowledge to know how to work with camera.

00:15.360 --> 00:17.160
We're going to use Cinemachine in this project.

00:17.160 --> 00:24.630
We need to go to Window Package Manager and in unity registry we need to find Cinemachine.

00:27.890 --> 00:28.670
There it is.

00:28.670 --> 00:30.200
So I'm going to just install it.

00:30.200 --> 00:32.780
It will take a couple of seconds, but not that long.

00:40.410 --> 00:47.250
Now we can go to one of the scenes, one of the levels, let's say level one, and we're going to set

00:47.250 --> 00:48.060
up camera here.

00:48.060 --> 00:49.980
I'm going to explain how it's going to work.

00:50.660 --> 00:53.120
So now let's add the camera.

00:53.120 --> 00:58.460
We're going to click create button Cinemachine targeted cameras to the camera.

00:58.760 --> 00:59.630
Very nice.

00:59.630 --> 01:00.830
So now we've got the camera.

01:00.830 --> 01:07.280
And before I explain any settings on the camera you should know that settings is usually overwritten

01:07.280 --> 01:10.370
on the main camera by the Cinemachine camera.

01:11.890 --> 01:17.980
So now, no matter what you do on the main camera, the Cinemachine camera will control the main camera

01:17.980 --> 01:21.460
and you need to do changes over here if you want them to work.

01:21.460 --> 01:24.160
There are some settings that can be changed.

01:24.160 --> 01:29.980
For example this one over here, but we don't really need to use it, so I guess that's irrelevant.

01:32.200 --> 01:32.770
All right.

01:32.770 --> 01:35.200
So main camera is controlled by the Cinemachine.

01:35.200 --> 01:37.180
But what is cinemachine itself?

01:37.420 --> 01:42.340
Well, uh, it may be, by the way, that your lens size is a bit different than mine.

01:42.340 --> 01:44.260
Just make sure you set it to what you want.

01:44.260 --> 01:48.580
And as example, I want to set value to six just like that.

01:48.940 --> 01:52.390
Now we also need to focus camera on the player.

01:52.390 --> 01:55.840
And for that we need to drag player to this field over here.

01:55.840 --> 01:57.010
Track and target.

01:57.010 --> 02:04.150
If you use previous version of unity like 22 or 21, you will have it say follow and you just drag your

02:04.150 --> 02:06.610
player to the follow field and it's going to work fine.

02:06.610 --> 02:07.750
Just same as mine.

02:07.750 --> 02:12.430
Now, even like that, with the default settings, we're going to have nice and dynamic camera.

02:12.430 --> 02:17.050
We can run around left and right, and you can see how alive the game feels.

02:17.050 --> 02:19.900
So if you like the look of it, you can just use it like that.

02:19.900 --> 02:21.490
You don't need to change anything.

02:21.490 --> 02:24.310
Personally me, I want to see the entire level.

02:24.310 --> 02:28.750
I want to have more of a precise platformer rather than fast paced platformer.

02:28.750 --> 02:33.280
So I want to set up camera in a way that you can see entire level, plenty of actions, and then do

02:33.280 --> 02:33.880
what you need.

02:33.880 --> 02:35.170
But maybe for you it's different.

02:35.170 --> 02:39.850
So let's talk about Cinemachine camera, and then I'm going to set it as I had before.

02:39.850 --> 02:46.120
The first problem we can see here is that we can see outside of the level, this area over here, I

02:46.120 --> 02:48.520
suppose it's not what we want to have in the game.

02:48.520 --> 02:53.050
So we need to give this camera a limitations to give it a limitation.

02:53.050 --> 02:54.700
We need to make an empty object.

02:54.700 --> 02:56.260
Let's do create empty.

02:56.710 --> 03:00.430
And I'm going to call it Cinemachine limits.

03:00.760 --> 03:01.540
Nice.

03:01.540 --> 03:04.690
Now for the limitations we need to give it a collider.

03:05.020 --> 03:08.980
Um, in the previous versions of unity you should use the Polygon Collider.

03:08.980 --> 03:12.160
So if you have 22 or 21, use Polygon Collider.

03:12.160 --> 03:17.890
If you have later version just like I do, then we can easily use Box Collider 2D.

03:19.650 --> 03:27.630
Let's place it in the center somewhere here, and then we can increase the size of the collider to something

03:27.630 --> 03:30.090
like 25 by 25.

03:30.390 --> 03:35.940
Then we can edit the collider, and this will define what player will be able to see.

03:35.940 --> 03:40.200
Basically, the visible area will be only inside of this collider.

03:40.200 --> 03:43.770
So you just need to decide what the player will see when he plays the game.

03:43.770 --> 03:49.890
I think my player will be able to see this much, so only this area inside of the collider is visible.

03:49.890 --> 03:55.470
Now, before we go ahead and apply this limitations to the camera, we need to disable collision of

03:55.470 --> 03:58.050
this collider with any objects on the level.

03:58.050 --> 04:02.100
We could do it through the layers, but that will take a bit of a time to set up.

04:02.100 --> 04:07.920
So instead I want to just click this trigger over here and now nothing will collide with it unless you

04:07.920 --> 04:09.960
have some specific functionality.

04:10.200 --> 04:18.780
Now let's go ahead to Cinemachine camera and we need to click Add Extension Cinemachine container to

04:18.780 --> 04:19.110
De.

04:19.970 --> 04:24.800
Now we have a new component over here, and this will allow you to limit movements of the camera.

04:25.040 --> 04:28.760
We can go ahead and just take cinemachine limits.

04:29.670 --> 04:32.100
And drag it here to the bounding shape.

04:33.090 --> 04:37.740
Now you'll see a message here, but it's not that important because once we start the game, it's going

04:37.740 --> 04:38.730
to just disappear.

04:38.760 --> 04:40.170
Let's go to play mode.

04:43.240 --> 04:44.380
And there it is.

04:44.410 --> 04:47.290
Now we cannot see what is outside of the level.

04:47.590 --> 04:50.170
And still camera moves as before.

04:50.680 --> 04:51.340
Very nice.

04:51.340 --> 04:52.600
That's just what we need.

04:53.580 --> 04:54.630
Yes.

04:54.630 --> 04:58.620
Now let's talk a bit about settings on this machine over here.

04:58.740 --> 05:00.840
First of all you can click save during play.

05:00.840 --> 05:05.730
So any changes will be applied to the component even when you exit the play mode.

05:06.330 --> 05:10.740
But I'm not going to do it because I want to explain things and then I want to have default settings.

05:10.740 --> 05:11.280
Okay.

05:12.650 --> 05:15.020
Now let's go through the settings one by one.

05:15.860 --> 05:21.050
The most important one, and some are not so important like these two.

05:21.870 --> 05:29.310
Camera distance defines how far your camera is from the object it follows and into deep perspective.

05:29.310 --> 05:31.920
It's not important like it's not relevant.

05:31.920 --> 05:37.320
You can just ignore it because it's only matter for 3D setup.

05:37.320 --> 05:42.000
But we have orthographic view with a 2D camera, so we don't need to worry about this one as well as

05:42.000 --> 05:43.080
the deadzone depth.

05:43.080 --> 05:45.960
Usually it's used for 3D, so just ignore it.

05:45.960 --> 05:51.360
There is also a screen position allows you to move a screen position as you like.

05:53.390 --> 06:00.230
Could be useful for some 2D games, like if you've seen a Cuphead or very old game contra.

06:00.650 --> 06:06.470
They have a view of something like this because you run from left to right, and you need to see all

06:06.470 --> 06:11.360
of the enemies above you in front of you, so you could do some sort of.

06:12.010 --> 06:17.530
Set up like this, and your character is always in the center of this point, so he can always see enemies

06:17.530 --> 06:19.540
in front of him that could be used.

06:19.540 --> 06:24.730
But for the platformer game, I don't think it's really a good idea because you need to see what is

06:24.730 --> 06:26.200
below you when you jump.

06:27.400 --> 06:30.310
So I'm going to set it to zero and zero.

06:31.150 --> 06:33.130
All right, let's talk about something else.

06:33.130 --> 06:33.700
Here.

06:33.700 --> 06:35.560
We have a dead zone.

06:35.560 --> 06:40.570
And that zone just gives a bit of a freedom to the movement of your character.

06:40.570 --> 06:44.620
If you enable it, you'll see a small area around the character.

06:44.620 --> 06:46.930
You can increase the area if you want.

06:49.640 --> 06:51.110
Uh, maybe just like that.

06:52.950 --> 06:56.730
And now when you move, your camera will not move.

06:57.030 --> 06:57.570
I'm sorry.

06:57.570 --> 06:58.890
I moved the position.

06:58.890 --> 06:59.310
Yeah.

06:59.310 --> 07:06.480
So your camera will not move until this yellow dot exits the dead zone area over here.

07:06.480 --> 07:10.740
So you are free to move inside of this area before you apply cameras movement.

07:10.740 --> 07:17.190
Now, if I jump outside of this area and my yellow dot will reach the limits, then I will move the

07:17.190 --> 07:20.010
camera to the left or right, as you can see.

07:20.010 --> 07:21.420
So it could be useful.

07:21.420 --> 07:24.240
For example, you have a character that can do like this.

07:24.600 --> 07:27.180
Then you could just set a very small dead zone.

07:29.100 --> 07:33.300
And it would give you a bit of movement before camera moves, but if you don't have it, you can notice

07:33.300 --> 07:36.570
that camera moves immediately once you do a small step.

07:37.130 --> 07:38.900
Now there is a hard limit.

07:38.900 --> 07:42.260
This one is more of a hard control of the camera.

07:42.290 --> 07:46.970
I'm going to decrease the size as much as I can over here to explain what it does.

07:47.270 --> 07:50.450
So, uh, usually Cinemachine follows.

07:50.450 --> 07:55.010
Not the player itself, but this yellow dot over here, that's what it follows.

07:55.010 --> 08:02.510
And this hard limit area will not allow this yellow dot to exceed the hard limits area.

08:02.510 --> 08:06.710
So now when I move, I, it moves a bit because we don't have a dead zone.

08:06.710 --> 08:12.920
But you can see no matter how hard I try, if my yellow dot reaches the limits, my camera moves immediately.

08:13.870 --> 08:14.680
Right.

08:15.330 --> 08:19.620
Now, of course it did exit the zone, but it's only because camera cannot move forward.

08:19.650 --> 08:24.990
There is a limit of a collider, so that's kind of, uh, um, higher rule here.

08:24.990 --> 08:30.150
But if camera can move freely inside of this area, you can see it follows the rule.

08:30.150 --> 08:33.990
It does not allow this yellow dot to exit the area.

08:35.900 --> 08:36.800
Of hard limits.

08:36.800 --> 08:41.450
And here, for example, again you can see camera is on its limits.

08:41.450 --> 08:42.680
It cannot go further.

08:42.680 --> 08:46.190
But for example, if you disable this container over here.

08:49.560 --> 08:50.040
Like that.

08:50.040 --> 08:51.300
You can see now.

08:54.630 --> 08:57.660
It never allows yellow dot to exit the area.

08:58.430 --> 08:59.090
Okay.

08:59.180 --> 08:59.810
Very good.

08:59.810 --> 09:04.040
Now let's enable container again and let's disable this hard limits.

09:04.370 --> 09:10.430
Now center on active is used when you switch between cameras or when you enable the camera basically

09:10.430 --> 09:11.270
does what it says.

09:11.270 --> 09:14.750
It will center on the object that it needs to follow.

09:15.380 --> 09:17.630
And then there is a target offset.

09:18.630 --> 09:24.720
So target is this yellow dot, and you can move the offset for this yellow dot to what you like.

09:25.050 --> 09:26.850
That's all about personal preference.

09:26.850 --> 09:29.130
And maybe there are some cases when it's needed.

09:29.460 --> 09:38.010
Um, main reason I can think of is 3D view of a third person shooter, for example, because you want

09:38.010 --> 09:43.620
your character to be somewhere here, but you cannot make camera follow the character, right?

09:43.620 --> 09:49.200
You need to make it follow yellow dot that could be moved with the offset.

09:50.830 --> 09:51.490
Yeah.

09:51.490 --> 09:52.840
So that's what it does.

09:52.870 --> 09:56.440
And dumping makes your camera move slower.

09:56.440 --> 10:00.640
So let's just use it and I'll explain how it works.

10:00.640 --> 10:04.840
Let's give it a dumping of 4x4 on x and y.

10:04.840 --> 10:08.080
And now you can see when I move my camera is not so fast anymore.

10:08.080 --> 10:09.730
It moves slower.

10:10.000 --> 10:12.010
So it could be used for some cases.

10:12.070 --> 10:19.000
Mostly I think about some maybe movement in the water or in the mountains where you need the slow movement

10:19.000 --> 10:19.750
of the camera.

10:19.750 --> 10:21.730
That could be done by not.

10:22.580 --> 10:26.570
Um, but again, it's always up to the game design of the game.

10:28.360 --> 10:36.880
Uh, for example, I had a top down shooter project and their camera followed the cross, the aim cross

10:36.880 --> 10:41.050
of the player, not the character itself.

10:41.050 --> 10:46.810
And when player moves his crosshair too fast, it makes it like it makes you feel dizzy.

10:46.810 --> 10:50.170
For that purpose, we can use damping to slow down movement of the camera.

10:50.170 --> 10:52.780
When you try to aim at different sides real quick.

10:52.780 --> 10:56.260
Same could work for 2D top down shooter for example.

10:56.260 --> 11:00.280
So I'm going to set it to one and there is last setting we need to talk about.

11:00.280 --> 11:01.570
It is look ahead.

11:01.570 --> 11:03.370
So if you increase look ahead.

11:03.430 --> 11:10.240
Your camera will try to predict the movement of the character and it will look in front of the player.

11:11.200 --> 11:14.830
Now it is a bit fast and it makes us dizzy again.

11:14.920 --> 11:16.840
Like I cannot understand what is happening.

11:16.840 --> 11:25.120
But if you increase smoothing over here, then it will be much easier to follow and see what is happening.

11:25.820 --> 11:26.090
Okay.

11:26.090 --> 11:29.810
So if you want to have smoothing, you could and you could also ignore why.

11:30.850 --> 11:31.540
And it will do.

11:31.570 --> 11:34.750
Look ahead only on the X, which is also pretty useful.

11:34.840 --> 11:37.240
So these are the settings that are there.

11:37.240 --> 11:40.390
And you can combine them to make the fill that you want.

11:40.390 --> 11:46.600
But for me, for my project and this is what I suggest we do in this game, we will set up view of the

11:46.600 --> 11:47.530
entire level.

11:47.530 --> 11:52.750
So I'm going to go to the lens over here, and I'm going to increase it to something like maybe nine.

11:53.670 --> 11:54.630
Or ten.

11:55.610 --> 11:55.940
Yeah.

11:55.940 --> 11:56.990
Let me try ten.

11:57.230 --> 11:57.890
Okay.

11:58.380 --> 11:59.430
So this is good.

11:59.430 --> 12:00.480
Now I have a camera.

12:00.480 --> 12:02.040
It looks same as before.

12:03.020 --> 12:07.010
And you might ask me, why do we need a new machine if it looks same as before?

12:07.010 --> 12:12.020
And I'm going to answer to you that we're just going to use a couple of nice techniques that we cannot

12:12.020 --> 12:13.730
do without seeing machine so easily.

12:13.730 --> 12:16.220
We're going to do camera shake and camera transition.

12:16.220 --> 12:19.250
And I'm going to show you that in this section.

12:19.250 --> 12:24.350
So let's save the project and let's go to the next video.
