WEBVTT

00:00.000 --> 00:00.480
Hello guys.

00:00.480 --> 00:01.440
Welcome to the video.

00:01.440 --> 00:04.560
In this one we need to work on a co-op camera.

00:04.560 --> 00:08.370
This means we will have to adjust the camera system quite a bit.

00:08.370 --> 00:11.280
It may take long, maybe 15 to 20 minutes.

00:11.280 --> 00:12.120
I'm not sure.

00:12.120 --> 00:13.620
The testing took a lot.

00:13.620 --> 00:14.880
So yeah, this.

00:14.880 --> 00:16.200
What are we going to do in this video?

00:16.200 --> 00:17.520
What the goal is.

00:17.520 --> 00:18.900
Let's define the goal.

00:18.900 --> 00:22.740
Our goal is to fit both players in the camera's view.

00:22.740 --> 00:25.710
Also, we want it to be a bit dynamic and active.

00:25.710 --> 00:29.190
And also we have a goal of making the camera follow one of the players.

00:29.190 --> 00:34.200
If only one of the players are in the game right now, and then when there is two players in the game,

00:34.200 --> 00:39.570
like when second player join in the game, then we need to center a camera between two players.

00:39.570 --> 00:45.810
And also if two players are going too far from each other, we want to zoom out the camera so it can

00:45.810 --> 00:48.570
see entire level and both players as well.

00:48.840 --> 00:50.610
Okay, that sounds like a lot.

00:50.610 --> 00:51.780
It's kind of a lot.

00:51.780 --> 00:54.090
So let's get to business, okay.

00:55.450 --> 01:02.740
First of all, we want to go ahead to this camera trigger and we want to disable these lines of code

01:02.740 --> 01:07.450
over here just for now, because they will enable and disable camera whenever they want.

01:07.450 --> 01:08.500
And we do need to do that.

01:08.500 --> 01:11.290
As of now we want to have manual control of everything.

01:11.560 --> 01:15.670
Also let's go to level camera and let's comment out this one.

01:16.790 --> 01:17.750
Very good.

01:17.780 --> 01:21.980
Now, first, uh, let's do something simple.

01:21.980 --> 01:24.050
Let's zoom out the camera.

01:24.050 --> 01:29.270
When players are getting too far from each other, or if, to be precise, when they getting out of

01:29.270 --> 01:30.650
the view of the camera.

01:31.190 --> 01:34.820
Uh, to show you what I mean by that, I'm going to make.

01:35.690 --> 01:41.360
An object camera center point, and it's going to be exactly in the center of the level.

01:41.420 --> 01:42.980
Now let's go to play mode.

01:45.280 --> 01:47.170
I'm gonna make two players.

01:48.880 --> 01:53.200
And let me take the camera and zoom in, maybe like eight.

01:54.260 --> 01:55.190
And let me make it.

01:55.190 --> 01:57.260
Follow the camera center point.

01:57.960 --> 01:58.620
Okay.

02:00.130 --> 02:02.110
So this is the center point.

02:02.440 --> 02:09.460
And let's say one player goes here, he exits the area and second player goes somewhere here.

02:10.530 --> 02:11.970
Right there.

02:11.970 --> 02:13.440
I cannot get there anyway.

02:13.440 --> 02:19.470
Now we want to zoom out the camera so both of them will stay in the view of the camera inside of the

02:19.470 --> 02:20.070
frame.

02:20.070 --> 02:21.540
How could we achieve that?

02:21.540 --> 02:24.540
Well, I found a solution, I guess.

02:24.540 --> 02:29.040
And before I show you that, I want to let you know that there is a component that's supposed to take

02:29.040 --> 02:34.860
care of this, you can go to extensions over here and there is a group framing, but I do not like how

02:34.860 --> 02:36.360
it works for me.

02:36.360 --> 02:38.820
I feel like it's moving too much.

02:38.820 --> 02:41.850
It just always shakes here and there, left and right.

02:42.770 --> 02:48.470
And there are not many parameters to set up this thing, so I prefer to use custom solution that is

02:48.470 --> 02:50.420
more suitable for our game.

02:50.420 --> 02:51.680
This is what we're going to do.

02:51.710 --> 02:53.660
We're going to make a new script.

02:54.920 --> 02:57.380
Level camera view.

03:00.040 --> 03:02.920
And we want to put Collider on the camera.

03:04.640 --> 03:09.860
Box Collider 2D and let's make it is trigger over here.

03:10.310 --> 03:15.590
Now let's adjust the size of a trigger, and it's going to be the frame that player are supposed to

03:15.590 --> 03:18.410
be in before we change the view.

03:18.530 --> 03:23.780
Let's say it's going to be 27 on the X and 18 on the Y.

03:25.410 --> 03:27.840
I know because I tried, so I know the values.

03:27.930 --> 03:32.850
Let's give offset on the y 2.2 and I want to see the box size.

03:32.880 --> 03:34.650
Um looks okay.

03:34.650 --> 03:36.240
Let's just try with this box size.

03:36.240 --> 03:37.860
Then we can adjust it if we want to.

03:37.890 --> 03:39.810
Now the goal is very simple.

03:39.870 --> 03:43.470
We want to go to the script of Level camera view.

03:43.470 --> 03:46.440
Let's put it on the cinemachine camera over here.

03:46.920 --> 03:47.520
And inside.

03:47.520 --> 03:52.770
We want to keep track of how many players are in the trigger at the moment, and if they're in the trigger,

03:52.770 --> 03:54.450
it means they're in the camera view.

03:55.200 --> 04:02.460
Okay, we could theoretically make the box size of a collider according to the size of the lens on the

04:02.460 --> 04:05.430
cinemachine, but I think it's an overkill.

04:05.430 --> 04:06.390
I don't really want to do it.

04:06.390 --> 04:07.830
I'll just do manual setup.

04:08.780 --> 04:11.000
So let me take the camera trigger.

04:11.000 --> 04:13.610
I want to take these methods from here.

04:13.610 --> 04:16.460
I'm going to copy go to Level Camera view.

04:16.460 --> 04:18.710
Paste this in over here.

04:19.820 --> 04:24.650
And then we need a variable just like we did in the last video private int.

04:25.350 --> 04:27.540
Players in view.

04:28.780 --> 04:32.650
Then over here we're going to do players in view Plus plus.

04:32.650 --> 04:40.240
And if players in view is bigger or equals to level camera and we need player list here.

04:40.240 --> 04:45.010
So I'm going to yeah we need player list here to know how many players there are supposed to be.

04:45.430 --> 04:47.500
Well as of now let's use player manager.

04:47.530 --> 04:48.190
All right.

04:48.980 --> 04:51.320
I'm going to do player manager instance.

04:51.320 --> 04:52.490
Get player list.

04:53.000 --> 04:54.020
What's up with you?

04:55.200 --> 04:56.910
Now we need to do dot count.

04:56.910 --> 05:02.760
So if players in view are the same amount as it's supposed to be, we can decrease the size of the lengths.

05:02.760 --> 05:04.770
We can take a closer look at the players.

05:04.770 --> 05:07.800
So we need to decrease size of lens.

05:08.310 --> 05:12.960
Then on the exit we want to do players in view minus minus.

05:12.960 --> 05:19.260
And if players in view is less than player manager dot instance get player list.

05:20.110 --> 05:21.190
Dot count.

05:21.310 --> 05:24.460
Then we need to, uh, zoom out the camera.

05:24.460 --> 05:26.560
So we need to increase the lens size.

05:27.520 --> 05:35.740
Increase the lens size, and we could directly do level camera cinemachine and increase the lens size,

05:35.740 --> 05:37.330
but that would be too snappy.

05:37.330 --> 05:40.300
I want to have a smooth change of value.

05:40.300 --> 05:46.480
That's why we're going to go to level camera and make a method that may look complicated, but actually

05:46.480 --> 05:47.590
it's super simple.

05:47.590 --> 05:48.220
All right.

05:49.100 --> 05:55.160
Let's go ahead and make a value private float target lens size.

05:55.160 --> 05:59.330
And I want to make it, uh, a serialized field because I want to show you how it works.

05:59.810 --> 06:01.490
Then in the.

06:02.420 --> 06:10.460
We're going to open up the gate and below let's make a method private void update lens size if needed.

06:10.670 --> 06:17.150
Okay, now inside of this method we want to check what is the current lens size we want to do.

06:17.150 --> 06:24.530
Float current lens size equals to Cinemachine lens orthographic size.

06:27.180 --> 06:28.680
Now we have current land size.

06:28.680 --> 06:33.090
We want to check if, uh, it is different from a target land size.

06:33.090 --> 06:38.520
We can do that by just checking the difference and seeing if this difference is bigger than very small

06:38.520 --> 06:38.910
value.

06:38.910 --> 06:44.730
Also, if we just take the difference between two values, it's going to be either negative or positive.

06:44.730 --> 06:47.610
But we want this check to work for both cases.

06:47.610 --> 06:54.870
For that we need to take math F absolute math f absolute absolute will always return you a positive

06:54.870 --> 06:55.230
value.

06:55.230 --> 06:56.970
And that is just perfect for us.

06:56.970 --> 07:02.340
Let's open a parenthesis and do current land size minus target land size.

07:02.340 --> 07:09.000
And if positive value of the difference is bigger than 0.5 f, it means it is different and we need

07:09.000 --> 07:10.920
to bring them closer to each other.

07:10.920 --> 07:16.800
If to be precise, we want to change land size and make it equals to target land size.

07:16.800 --> 07:19.800
We can do that smoothly with the help of a lerp.

07:19.800 --> 07:21.030
We're going to do float.

07:21.030 --> 07:30.570
New lens size equals to math f dot lerp from current land size to a target lens size.

07:30.570 --> 07:39.210
And let's do time step of 0.5 f, multiply it by time dot delta time so it will be smooth and nice.

07:39.270 --> 07:44.370
And then we want to take cinemachine lens orthographic size equals to new lens size.

07:44.370 --> 07:48.270
And because of that it's going to smoothly increase or decrease the lens size.

07:48.270 --> 07:48.870
You'll see.

07:48.870 --> 07:54.630
Now also if difference is not very big, like if difference is very small, then we can just snap it

07:54.630 --> 07:56.280
to the value that we want to have.

07:56.280 --> 08:03.180
Cinemachine lens orthographic size equals to target lens size.

08:03.420 --> 08:06.570
Okay, now let's update this value in the update.

08:07.650 --> 08:09.810
Update lens size if needed.

08:09.810 --> 08:13.170
I'm going to save it and I want to go to update.

08:13.170 --> 08:15.660
I mean to unity and show you how it works.

08:15.660 --> 08:18.120
Now we're going to go to Level Camera.

08:20.490 --> 08:24.780
And let's say we know the land size now is nine, or actually it is ten.

08:24.780 --> 08:26.340
Let's make it as nine.

08:28.370 --> 08:29.090
And over here.

08:29.090 --> 08:31.220
Target lenses by default is nine.

08:31.760 --> 08:33.230
Now let's go to play mode.

08:35.670 --> 08:38.760
And we can see camera is not moving, everything is fine.

08:38.760 --> 08:42.120
And if we change the target value to ten.

08:43.430 --> 08:45.650
It's going to zoom out just like that.

08:45.650 --> 08:48.740
If you change target value to lower like five.

08:48.770 --> 08:50.120
It's going to zoom in.

08:50.120 --> 08:55.250
So this allows you to have method that changes zoom of the camera when you want to.

08:57.050 --> 09:02.870
And now we can just change this value through the method to make camera zoomed in or zoomed out.

09:02.870 --> 09:07.250
And that will depend on the amount of players we have in the camera's view.

09:08.040 --> 09:12.420
Let's make a method public void change camera.

09:13.560 --> 09:15.090
Lens size.

09:15.090 --> 09:20.940
We're going to pass a float size and we're going to do target lens size equals to size.

09:23.040 --> 09:23.760
Nice.

09:23.760 --> 09:26.100
Now let's go back to this level camera view.

09:26.700 --> 09:30.360
And over here we want to change value to uh.

09:31.230 --> 09:32.250
Different one.

09:32.250 --> 09:36.330
Well, we can hard code the value or we can make a variable.

09:36.840 --> 09:39.750
That is up to you I think.

09:39.750 --> 09:39.930
Yeah.

09:39.930 --> 09:41.850
Let's do variables on a level camera.

09:44.410 --> 09:51.490
Let's make public float mean camera size and public float max camera size.

09:51.610 --> 09:52.690
Now I'm going to save it.

09:52.690 --> 09:54.910
And I'm going to go back to level Camera view.

09:55.270 --> 09:57.340
And over here we're going to do level camera.

09:59.380 --> 10:02.590
Change camera lens size to level camera.

10:03.220 --> 10:04.840
And here we zoom in in.

10:04.840 --> 10:07.420
So I'm going to do mean camera size.

10:08.020 --> 10:15.880
Over here we're going to do level camera change camera lens size to level camera max camera size okay.

10:15.880 --> 10:17.200
This is supposed to work.

10:17.200 --> 10:20.440
Let me remove this and let's go ahead and try this.

10:25.910 --> 10:27.770
Oh, I forgot to change values.

10:28.810 --> 10:30.880
Let's do a minimum camera size nine.

10:30.880 --> 10:32.740
Maximum camera size ten.

10:33.250 --> 10:35.200
Also, we don't need to see this value anymore.

10:35.200 --> 10:36.340
We know how it works.

10:36.340 --> 10:39.490
So I'm going to go back here I'm going to hide it.

10:40.700 --> 10:44.900
And just in case, I'm going to go to awake and I'm going to do target lens size.

10:46.780 --> 10:51.070
Equals to um cinemachine lens.

10:51.310 --> 10:52.390
Orthographic size.

10:52.390 --> 10:56.350
So by default it will take value that we have on the camera at the moment.

10:56.380 --> 10:56.830
Okay.

10:56.830 --> 10:58.690
So we don't have to change it every time.

11:01.060 --> 11:02.560
Now I'm going to go to play mode.

11:04.760 --> 11:06.770
Camera will look in the center.

11:07.160 --> 11:12.320
I will add the player and then I'll try to walk out of the area.

11:12.590 --> 11:14.210
The area is.

11:14.810 --> 11:15.590
Where is it?

11:16.560 --> 11:18.780
The area is over here.

11:18.780 --> 11:21.840
This is the collider that is barely visible and I'll try to.

11:22.900 --> 11:24.460
Jump out of that area.

11:26.940 --> 11:27.990
I cannot jump there.

11:27.990 --> 11:33.570
Well, I can go here and we can see that camera is zooming out slowly, which is very nice and very

11:33.570 --> 11:34.200
pretty.

11:34.230 --> 11:38.880
Now I'm going to go back and we zooming in so we can see both players.

11:39.670 --> 11:40.810
Very cool, I love it.

11:40.810 --> 11:42.520
Let me try to work out again.

11:43.990 --> 11:45.220
And we zoom in out.

11:45.250 --> 11:46.630
It feels a bit snappy.

11:47.350 --> 11:49.180
I wonder why it should be smooth.

11:49.210 --> 11:52.180
Maybe just because of the structure of the level.

11:52.180 --> 11:54.430
Well, it doesn't really matter because we're going to adjust it more.

11:54.430 --> 11:58.330
And that will fix the problem with the shaking over there like we see right now.

11:59.890 --> 12:01.780
Okay, so what is the next goal?

12:02.200 --> 12:05.170
Now we cannot keep camera just in the center like that.

12:05.170 --> 12:07.300
I want it to be a bit dynamic.

12:07.300 --> 12:08.680
I want it to move around.

12:09.580 --> 12:11.620
And for that we can place camera.

12:12.420 --> 12:16.530
Center between two points if there are two players in the game.

12:16.830 --> 12:18.270
If we want to do that.

12:19.310 --> 12:26.240
We need to go to level camera, and we need to check how many players there are in the game right now.

12:28.090 --> 12:34.120
Um, we can make a private list of player.

12:37.620 --> 12:39.060
Player list.

12:39.730 --> 12:42.910
And let's let's maybe make it public.

12:44.080 --> 12:47.050
Public yet private set.

12:50.040 --> 12:54.480
Now we can use this list on a level camera view over here instead of player manager.

12:55.820 --> 12:59.270
Mobile camera player list dot count.

12:59.270 --> 13:00.560
Same goes here.

13:04.180 --> 13:06.730
The on camera player list count.

13:07.150 --> 13:07.990
Nice.

13:08.110 --> 13:11.380
And then let's go to level camera and adjust it slightly.

13:15.370 --> 13:18.520
First of all, we want to have the center point.

13:19.940 --> 13:21.950
So I'm going to make satellites field private.

13:21.980 --> 13:25.520
Transform camera center point.

13:25.520 --> 13:28.430
And this is the point we're going to place between two players.

13:28.550 --> 13:32.720
Now let's go and make a method that would update camera status.

13:32.720 --> 13:38.510
And we can update camera status every time player joins or disconnects from the game.

13:38.870 --> 13:41.240
I'm going to make a method over here.

13:42.400 --> 13:49.030
Private void update camera status in which we want to update, uh, list.

13:49.030 --> 13:52.270
So I'm going to do player list equals to player manager.

13:52.270 --> 13:54.910
That instance get player list.

13:54.910 --> 14:01.630
Then we want to see if player list count is bigger than one, means we have more than one player in

14:01.630 --> 14:02.200
the game.

14:02.200 --> 14:06.010
And if that's the case then we want to focus camera on a center point.

14:06.010 --> 14:09.430
I'm going to set new target camera center point.

14:09.580 --> 14:11.620
Also you can see we have a misspelling over there.

14:11.620 --> 14:12.790
So I'm going to fix it.

14:15.940 --> 14:20.680
Then else means if we don't have more than one player in the game, we're going to focus camera on the

14:20.680 --> 14:22.240
first player in the list.

14:22.240 --> 14:28.270
Set new target layer list with a zero dot transform very well.

14:28.420 --> 14:30.700
So this will update the camera status.

14:30.700 --> 14:32.410
We just need to call this method.

14:33.150 --> 14:36.270
Uh, like at the right moment of the game.

14:37.150 --> 14:40.990
I think it's better to do this when player dies or respawns.

14:40.990 --> 14:43.660
So I'm going to go all the way below over here.

14:44.230 --> 14:45.880
And I'm going to do on enable.

14:47.860 --> 14:48.790
Player manager.

14:49.390 --> 14:49.780
Uh.

14:49.780 --> 14:50.620
On player.

14:50.620 --> 14:51.370
Respawn.

14:51.970 --> 14:52.810
Plus equals.

14:52.810 --> 14:53.380
Update.

14:53.380 --> 14:54.640
Camera status.

14:55.620 --> 14:59.820
Player manager on player death update camera status.

14:59.820 --> 15:01.650
Also we need to unsubscribe from this.

15:01.650 --> 15:03.240
So on disable.

15:04.050 --> 15:06.030
Let's take these two lines of code.

15:06.150 --> 15:07.410
Paste them in here.

15:08.630 --> 15:09.140
And do.

15:09.140 --> 15:09.950
Minus.

15:10.310 --> 15:11.240
Minus.

15:11.510 --> 15:14.060
Okay, let's save this.

15:14.390 --> 15:16.040
Uh, let's go back.

15:17.880 --> 15:20.460
And we could call it in the update.

15:20.460 --> 15:22.950
And this supposed to do half of the job.

15:23.460 --> 15:30.150
We also want to find a midpoint between two players and place this center point between two players.

15:34.100 --> 15:36.200
Actually, it's not that difficult to do.

15:36.620 --> 15:39.050
Let's make a method.

15:40.130 --> 15:45.110
Public void update center point position.

15:45.620 --> 15:49.130
And over here we just want to get transform of two players.

15:49.130 --> 15:52.370
Find the midpoint between them and then place camera there.

15:52.370 --> 15:57.500
To do that we need to have reference to players transform and we could get them from the list.

15:57.500 --> 16:02.480
But I want to have a clear variable so we understand what it does and why we use it like that.

16:02.480 --> 16:07.010
So I'm going to do private transform P1 private transform P2.

16:08.250 --> 16:08.640
Let's do.

16:08.640 --> 16:09.630
Player one.

16:10.200 --> 16:11.190
Player two.

16:11.370 --> 16:12.150
Okay.

16:12.360 --> 16:14.520
Now we're going to go to this.

16:14.640 --> 16:21.660
Oh, and also I want to have a boolean that says private bool camera focused on center.

16:23.310 --> 16:24.990
Now let's go to this method.

16:24.990 --> 16:29.190
And if we have more than one player in the game and we updated the list, then we want to do player

16:29.190 --> 16:34.740
one equals to player list zero transform player two player list.

16:35.380 --> 16:39.820
One transform and camera focused on center.

16:39.820 --> 16:40.450
True.

16:40.810 --> 16:43.630
If you don't have the players camera focused on center.

16:43.630 --> 16:44.530
False.

16:44.530 --> 16:45.430
Very nice.

16:45.430 --> 16:48.520
Let's save this and let's go back to this method.

16:48.520 --> 16:53.020
First of all, if camera focused on center is equals to false, we're going to return from here.

16:53.020 --> 16:55.240
So we're not going to update center position.

16:55.240 --> 16:58.960
And if we do then we need to do Vector3 midpoint.

16:58.960 --> 17:01.570
And this will be middle point between two players.

17:01.720 --> 17:04.840
We can easily get it by typing player one.

17:05.880 --> 17:13.200
Dot position plus player two dot position divided by two, and this will give us a middle point between

17:13.200 --> 17:14.250
two objects.

17:14.250 --> 17:19.530
And now we can take a camera center point dot position equals to midpoint.

17:19.530 --> 17:23.310
Now the goal is to update position at all times.

17:23.310 --> 17:26.250
But I think I don't want to do this in the update.

17:27.330 --> 17:28.620
That could be too often.

17:28.620 --> 17:33.210
So let's go to awake over here and let's invoke this method with repeating.

17:33.570 --> 17:35.130
Invoke repeating.

17:35.160 --> 17:40.170
You're going to do name of update camera center point position.

17:41.630 --> 17:42.560
And zero delay.

17:42.560 --> 17:43.610
Repeat rate.

17:44.680 --> 17:45.670
Point one F.

17:46.030 --> 17:48.400
This is pretty often, but not too often.

17:48.460 --> 17:52.090
Okay, so yeah, it was kind of fast.

17:52.090 --> 17:53.380
I'm sorry if it was fast.

17:53.380 --> 17:55.690
I just, you know, I'm going to tell you a secret.

17:55.690 --> 17:59.230
I'm recording this video for the fourth time's.

17:59.230 --> 18:04.990
Yeah, I did try 4 or 5 times and I couldn't get the flow right where I am explaining everything in

18:04.990 --> 18:06.610
a needed and needed order.

18:06.610 --> 18:09.610
So I had to start over again and again.

18:09.610 --> 18:10.270
Again and again.

18:10.270 --> 18:13.420
And that might be why I'm going a little bit fast here.

18:13.420 --> 18:17.890
I hope you can forgive me for that, especially in the end of the course.

18:18.220 --> 18:18.970
Yeah.

18:18.970 --> 18:20.260
By the way, congratulations.

18:20.260 --> 18:21.460
We are finishing up soon.

18:22.460 --> 18:24.080
Now let's go back to unity.

18:24.620 --> 18:27.860
And we have this camera center point over here.

18:27.860 --> 18:30.980
So I'm going to just assign it into this field.

18:30.980 --> 18:32.450
And I want to take center point.

18:32.450 --> 18:35.180
And I want to give it a gizmo so I can see it.

18:35.750 --> 18:37.730
Now this is supposed to do the job.

18:37.730 --> 18:38.930
Let's go to play mode.

18:43.030 --> 18:44.440
There is one player.

18:44.920 --> 18:46.000
Very nice.

18:46.570 --> 18:50.980
It is focused on the player and it feels pretty dynamic, I like it.

18:51.130 --> 18:54.820
Now I'm going to add another player and now camera is between them.

18:54.820 --> 18:58.240
We can enable gizmos and we can see the dot over here.

18:58.300 --> 19:00.730
If I go there and if I.

19:02.320 --> 19:04.060
Maybe jump over the player camera.

19:04.090 --> 19:04.900
Going to be dynamic.

19:04.900 --> 19:07.150
It's going to move to the sides.

19:07.300 --> 19:08.920
Very nice I love it.

19:10.090 --> 19:10.390
And.

19:10.390 --> 19:11.680
Yeah, I got here.

19:11.710 --> 19:16.000
Now, let me try to walk away from the player and it's supposed to zoom out.

19:16.000 --> 19:17.290
Yeah, it did zoom out.

19:17.290 --> 19:18.640
Very nice and clean.

19:18.790 --> 19:20.950
Almost unnoticeable really.

19:20.950 --> 19:23.140
We can see two players in the level.

19:23.140 --> 19:26.380
And if I come closer, it's going to nicely zoom in.

19:28.480 --> 19:35.020
Also, you probably noticed that just now I could see a bit of a, uh, blue background over here.

19:36.710 --> 19:40.310
It may happen sometimes because camera, you know, it's very difficult to manage.

19:40.310 --> 19:41.990
There are so many things considered.

19:41.990 --> 19:47.810
And what you could do is just draw the level around the playable area over here.

19:47.810 --> 19:50.870
Just add some parts to hide it.

19:52.440 --> 19:53.310
Just like that.

19:53.960 --> 19:57.590
Also, you could go to, um.

19:59.140 --> 20:01.600
Main camera over here.

20:01.600 --> 20:07.690
Find the background and take Color Picker and choose background.

20:08.170 --> 20:09.430
Uh, just like this one.

20:09.430 --> 20:10.840
Let's just click it on it.

20:11.840 --> 20:15.950
Okay now in the game, even if you don't have area there.

20:17.600 --> 20:20.180
It will look just like a background of the level.

20:20.210 --> 20:22.160
Let me show you that I'm going to just.

20:24.170 --> 20:26.990
Remove here everything.

20:29.640 --> 20:32.610
Here you can see it looks dark blue, so it's fine.

20:32.610 --> 20:37.230
So if it is outside of the level, it's going to just show you this background and it does not look

20:37.230 --> 20:38.220
like a bug.

20:39.150 --> 20:39.960
Okay.

20:39.960 --> 20:40.890
Very well.

20:42.030 --> 20:42.570
Now.

20:42.570 --> 20:43.770
We did a lot.

20:43.860 --> 20:49.020
I can see it's about 20 minutes now, but we still have to do one more adjustment here.

20:49.020 --> 20:51.180
And to do this adjustment, we better go.

20:51.180 --> 20:53.370
We better go to another level.

20:54.800 --> 20:57.290
Now let's take camera manager level camera.

20:57.290 --> 20:59.240
Let's apply overrides.

21:00.180 --> 21:00.750
Apply.

21:00.750 --> 21:05.220
So now this camera has everything that is needed to make it work.

21:05.220 --> 21:08.190
And we can go to scene level four.

21:08.190 --> 21:09.450
I'm going to save it.

21:09.450 --> 21:12.660
And on this level we have two areas.

21:13.110 --> 21:15.210
Area one and area two.

21:15.240 --> 21:20.910
Now I don't want one of the players to go further without second player joining him.

21:20.910 --> 21:26.250
If there is only one player entered next room, then he's supposed to wait for the first player to enter.

21:26.250 --> 21:28.710
This is what we need to do, how it's going to be.

21:28.710 --> 21:31.140
We're going to place invisible colliders.

21:31.140 --> 21:36.720
The player cannot pass by and we're going to disable this colliders only when two players entered the

21:36.720 --> 21:37.290
room.

21:39.010 --> 21:39.910
The rom rom.

21:39.910 --> 21:40.330
Yeah.

21:40.720 --> 21:44.680
So this one we're going to do we're going to go.

21:47.250 --> 21:48.570
We're going to go.

21:50.400 --> 21:51.540
Let's say here.

21:51.540 --> 21:55.050
Let's make 2D object sprite square.

21:56.610 --> 21:58.770
I'm going to name it as, uh, maybe.

21:59.510 --> 22:01.460
Level limits.

22:01.820 --> 22:06.200
Not sure it's supposed to be under the camera, but this is a pretty good place for it because functionality

22:06.200 --> 22:07.100
going to be here.

22:08.140 --> 22:12.010
And we're going to just take these limits and let's say place it somewhere.

22:13.330 --> 22:14.020
Here.

22:14.230 --> 22:17.770
Let's do player minus one so I can see it.

22:18.100 --> 22:19.450
And I'm going to just.

22:20.370 --> 22:21.990
Make it white like that.

22:23.090 --> 22:25.460
Also let me take checkpoint and move it here.

22:25.940 --> 22:27.560
So now we have this level limit.

22:27.920 --> 22:29.240
It is a collider.

22:29.240 --> 22:35.630
We want to add box Collider 2D here and we want it to be unpassable only for players.

22:35.630 --> 22:37.460
So let's make a layer.

22:39.360 --> 22:40.710
Layers.

22:40.920 --> 22:42.090
Limits.

22:42.540 --> 22:45.360
We're going to go to Edit Project Settings.

22:45.990 --> 22:50.310
And over here we need to disable collision for everything but a player.

22:51.090 --> 22:51.840
Nice.

22:51.840 --> 22:52.920
Gonna close it.

22:54.810 --> 22:57.330
And then we need to go to.

22:57.360 --> 22:57.960
I'm sorry.

22:57.960 --> 22:58.890
I need to think a bit.

22:58.890 --> 23:03.720
We need to go to level camera because I think we can centralize everything and then just call method

23:03.720 --> 23:04.470
from here.

23:04.980 --> 23:06.600
And we want to make array.

23:08.370 --> 23:09.390
Serialize field.

23:09.390 --> 23:10.050
Private.

23:10.900 --> 23:11.890
I'm going to do it here.

23:11.890 --> 23:15.880
Collider 2D array limits.

23:16.390 --> 23:20.200
Then we want to make a method that will disable or enable these limits.

23:21.660 --> 23:22.890
So.

23:23.910 --> 23:24.870
What are we going to do?

23:28.670 --> 23:30.410
Over here we have enable camera.

23:30.440 --> 23:36.170
I'm also going to do a public void enable limits.

23:37.090 --> 23:45.850
Bool enable, then we're going to do for each var collider in colliders are in limits we're going to

23:45.850 --> 23:46.960
do Collider.

23:50.900 --> 23:52.250
Collider enabled.

23:52.250 --> 23:52.910
Enable.

23:55.240 --> 23:57.850
So this one can disable or enable limits.

23:57.850 --> 24:02.920
Also, since we're doing this, let's make a variable that says that camera is enabled.

24:03.280 --> 24:04.180
I'm going to do.

24:05.680 --> 24:05.860
Right.

24:05.860 --> 24:08.950
Red bull camera active maybe like that.

24:08.950 --> 24:13.690
And I want to disable all of the functionality if camera is not active.

24:13.690 --> 24:15.550
So if camera active.

24:16.330 --> 24:21.220
False return then over here as well if camera active.

24:21.220 --> 24:22.060
False.

24:23.500 --> 24:26.080
Return and.

24:28.490 --> 24:29.570
Over here as well.

24:29.570 --> 24:32.960
If camera active polls return.

24:33.410 --> 24:34.130
Nice.

24:36.280 --> 24:37.600
And this one should be okay.

24:37.600 --> 24:38.860
We don't need to update this one.

24:38.860 --> 24:41.800
This one will not be called because we need to return in the update.

24:41.800 --> 24:46.330
We just need to go here and do camera active equals to enable.

24:47.170 --> 24:47.980
Nice.

24:48.070 --> 24:50.440
Now let's go back to level camera trigger.

24:50.440 --> 24:51.790
The one we had before.

24:52.120 --> 24:53.740
It is over here.

24:53.890 --> 24:58.420
And we did enable camera if player entered the area.

24:58.420 --> 24:59.920
And then we disable the camera.

24:59.920 --> 25:02.260
If player exit the trigger.

25:02.260 --> 25:08.920
Now we want to disable the camera only if two players are exiting the trigger or two players entering

25:08.920 --> 25:12.850
the trigger, and actually the amount of players that is supposed to be in the game right now.

25:12.850 --> 25:14.560
So this is what I'm going to do.

25:14.560 --> 25:17.320
I'm going to make private int.

25:18.360 --> 25:20.070
Players in.

25:20.920 --> 25:21.730
Trigger.

25:22.680 --> 25:26.850
Then every time somebody enters the trigger, we're going to do player sin, trigger plus plus.

25:26.850 --> 25:28.830
Then we want to open if statement.

25:28.830 --> 25:34.230
And inside of this if statement we're going to do if player sin trigger is equals to level camera player

25:34.230 --> 25:39.300
list dot count then level camera enable.

25:40.380 --> 25:40.950
Tamara.

25:41.280 --> 25:42.060
True.

25:42.090 --> 25:45.510
Then we need level camera enable limits.

25:45.510 --> 25:49.020
True because we want to block exits out of this room.

25:49.320 --> 25:56.520
Then this one can be removed and we can go over here and do player scene trigger minus, minus.

25:56.520 --> 26:03.090
And then if player since trigger is equals to zero means there is no players in the room anymore, we

26:03.090 --> 26:07.080
can, uh, unlock the doors and we can disable the camera.

26:07.080 --> 26:09.750
So I'm going to do level camera, enable camera.

26:10.620 --> 26:13.320
Balls and level camera enable limits.

26:13.320 --> 26:14.070
False.

26:14.100 --> 26:16.380
Okay, let's save this.

26:16.380 --> 26:20.070
Let's go back to unity.

26:21.350 --> 26:24.560
And I'm going to have a level limit over here.

26:27.230 --> 26:28.730
For this room.

26:28.730 --> 26:33.800
And this one basically means that we cannot exit from here until there is two players on the level.

26:33.800 --> 26:35.180
Okay, that's the idea.

26:38.170 --> 26:41.050
Uh, something like this should be fine.

26:42.400 --> 26:43.120
Okay.

26:43.330 --> 26:47.470
And then for this camera over here, let me duplicate it.

26:48.630 --> 26:49.950
Actually, I think we can just.

26:51.350 --> 26:52.790
Apply overrides.

26:52.820 --> 26:54.500
Now this one has level limit.

26:54.500 --> 26:55.970
I'm going to enable camera.

26:55.970 --> 26:57.530
I'm going to take level limit.

26:57.530 --> 26:59.720
And I'm going to place it over here.

26:59.720 --> 27:01.460
So we cannot go back alone.

27:01.460 --> 27:03.590
We can go back only together.

27:03.590 --> 27:07.370
You getting the point right for this area.

27:07.370 --> 27:12.080
Exit is blocked over here for this area.

27:12.500 --> 27:14.240
Exit is blocked over here.

27:14.240 --> 27:19.580
And if you have more exits, you can just add another game object and assign it into the.

27:20.660 --> 27:21.650
Array over here.

27:21.650 --> 27:23.060
Let me assign it here.

27:23.060 --> 27:25.580
And for this room should be here.

27:26.120 --> 27:26.870
Okay.

27:28.990 --> 27:30.010
Very good.

27:30.040 --> 27:32.500
Now everything's supposed to work.

27:32.500 --> 27:35.110
I think we did pretty much everything that we need.

27:35.110 --> 27:37.210
And let's go and try this.

27:38.160 --> 27:39.150
Can I go to game mode?

27:39.180 --> 27:40.590
Going to go to play mode.

27:40.590 --> 27:42.660
Oh, wait a second, I think I forgot something.

27:42.660 --> 27:47.580
We need to take level limits and we need to change layer to players limit.

27:48.210 --> 27:50.370
Now I'm going to apply overrides again.

27:51.250 --> 27:53.140
Let's enable second camera.

27:54.270 --> 27:55.440
That looks good to me.

27:56.010 --> 27:57.450
Now let's go to play mode.

27:57.840 --> 27:59.910
Also why it is showing this view right now.

28:05.900 --> 28:09.080
Let me do minus one over here so it does not bother me.

28:09.080 --> 28:09.710
Okay.

28:09.710 --> 28:11.300
So it has less priority.

28:11.330 --> 28:13.190
Now let's go to play mode.

28:15.490 --> 28:20.260
I'm going to join the player, and I can see that camera did not focus on the player.

28:20.860 --> 28:21.550
Okay.

28:21.550 --> 28:23.170
Maybe I made a mistake.

28:23.170 --> 28:24.670
Let's go to level camera.

28:27.000 --> 28:27.240
Uh.

28:27.240 --> 28:28.020
Over here.

28:28.020 --> 28:30.630
Let's not return when we update camera status.

28:30.630 --> 28:32.250
I think this what breaks.

28:33.200 --> 28:34.220
The deal.

28:34.220 --> 28:35.180
Going to save it?

28:35.180 --> 28:36.530
I'm going to try again.

28:39.610 --> 28:42.880
Let's go to Game View and let's go to play mode.

28:46.410 --> 28:46.830
All right.

28:46.830 --> 28:48.090
There is player one.

28:48.270 --> 28:50.160
Camera follows the player one.

28:50.580 --> 28:51.600
Very nice.

28:51.630 --> 28:53.280
Now let's make a second one.

28:53.280 --> 28:55.050
And there is a second player.

28:55.620 --> 28:56.250
Okay.

28:56.250 --> 28:57.150
Very good.

28:58.510 --> 29:00.520
Now let's try to walk here.

29:00.550 --> 29:01.990
Camera zooming out.

29:01.990 --> 29:04.540
I like it so we can see both of them.

29:05.120 --> 29:07.370
Now let me get the second layer there.

29:10.320 --> 29:12.420
I know Mushroom Hill.

29:13.970 --> 29:14.540
Now.

29:14.540 --> 29:16.100
First player goes here.

29:16.830 --> 29:17.400
Oh.

29:18.350 --> 29:20.210
It should be disabled by default.

29:20.540 --> 29:21.980
Now let me go there.

29:22.340 --> 29:23.720
Let me take level limits.

29:23.750 --> 29:25.160
Let me disable it.

29:27.880 --> 29:32.860
I just disabled the door from a second level because this one should be disabled by default.

29:32.890 --> 29:36.010
Okay, so I can go there, but I cannot go further.

29:36.010 --> 29:37.390
I can only return.

29:37.870 --> 29:39.040
This is good.

29:39.070 --> 29:41.650
Now let's try to walk there together.

29:42.520 --> 29:46.510
And yes, we did change the view to another level.

29:46.510 --> 29:47.800
This is all good.

29:47.800 --> 29:50.500
And also, if we want we can walk back.

29:50.500 --> 29:51.460
Let's go by the.

29:52.790 --> 29:54.500
And both of us here.

29:55.240 --> 29:56.050
Okay.

29:56.930 --> 29:57.560
Very nice.

29:57.560 --> 30:00.320
It works, I love it, I love the system.

30:00.320 --> 30:02.750
This looks so cool and feels so nice.

30:03.440 --> 30:04.460
Uh, let's.

30:05.680 --> 30:11.860
Go to level camera and in the wake I'm going to disable level limits.

30:12.940 --> 30:13.240
Wait.

30:13.240 --> 30:14.920
Enable limits.

30:15.760 --> 30:16.060
Polls.

30:16.060 --> 30:20.680
So we're going to disable limits in their wake, but then we're going to enable them when player is

30:20.680 --> 30:22.420
joining the game.

30:22.420 --> 30:22.930
Right.

30:32.540 --> 30:34.070
Okay, I think that's it.

30:34.100 --> 30:35.810
Now let's take these limits.

30:37.400 --> 30:39.440
Let's make them transparent.

30:40.580 --> 30:42.440
Just like that, so it's not visible.

30:42.440 --> 30:44.840
And let's go to the next video.

30:45.140 --> 30:45.830
Yay!
