WEBVTT

00:00.040 --> 00:06.320
Now we're gonna make the cinemachine camera stick with our Cinemachine camera, so we will select our

00:06.320 --> 00:12.680
Cinemachine camera in the hierarchy, go over to Inspector, then Cinemachine camera, and in the bottom

00:12.680 --> 00:15.120
you can see noise and it says none.

00:15.120 --> 00:18.920
So just click there and choose this basic multi-channel Perlin.

00:19.120 --> 00:25.600
And as soon as we clicked on it and if we scroll down to the bottom, we can see a component just added

00:25.600 --> 00:29.360
up, which is Cinemachine basic multi-channel Perlin component.

00:29.600 --> 00:33.880
And we can see noise profile and it says noise setting.

00:33.880 --> 00:36.640
So what we need to do we need to select 66.

00:36.680 --> 00:39.360
So just click in this settings icon.

00:39.360 --> 00:42.640
In the right side you can see basically the icon.

00:42.760 --> 00:47.520
Then go over to presets and then choose the 6666.

00:47.720 --> 00:53.520
And now if we go ahead and then click on this play button, you will see as soon as our game just gonna

00:53.520 --> 00:59.240
start, the camera will start shaking with this amplitude gain and this frequency gain.

00:59.520 --> 01:01.360
So firstly what you need to do.

01:01.400 --> 01:06.800
You basically need to move over to Cinemachine camera and then you need to choose choose this noise

01:06.800 --> 01:09.080
profile to basic multi-channel burning.

01:09.480 --> 01:11.920
So just wait a little moment.

01:13.200 --> 01:20.200
So as you can see, as soon as our game just started, camera started shaking and we can just play around

01:20.200 --> 01:21.040
with the value.

01:21.040 --> 01:26.520
So if I move over to my inspector, scroll down to Cinemachine basic multi-channel Perlin component

01:26.720 --> 01:30.720
and increase this amplitude gain something like two.

01:30.880 --> 01:37.200
As you can see, it's shaking more instantly and we can play around with the frequency gain as well

01:37.360 --> 01:38.360
as well.

01:38.360 --> 01:45.360
So we can see camera is shaking with too much fast, basically, uh, too much with too much intensity.

01:45.720 --> 01:51.920
And if we set back this amplitude back to zero, we can notice that camera stops shaking.

01:51.920 --> 01:57.280
And if we set this amplitude gain to some numbers with some numbers something, let's suppose two.

01:57.440 --> 01:59.720
We can notice that it's shaking.

01:59.720 --> 02:07.390
But once we set back this amplitude gain to zero, we can notice that the camera just stops shaking.

02:07.470 --> 02:13.390
So what we basically need we need a reference of this cinemachine basic multichannel Berlin component.

02:13.390 --> 02:17.590
And then we can just access the value and we can just do that.

02:17.670 --> 02:19.550
So I'm going to get out of play mode.

02:19.550 --> 02:26.150
And by default amplitude again I'm gonna set it to zero since I don't want my camera to check right

02:26.150 --> 02:27.430
after the game start.

02:27.430 --> 02:31.470
And I want to increase the frequency gain to something around two.

02:31.830 --> 02:34.190
So firstly, what you need to do, let me explain.

02:34.230 --> 02:35.790
What one more time.

02:35.830 --> 02:41.190
Select your cinemachine camera in the hierarchy, then go over to Inspector, then Cinemachine camera

02:41.190 --> 02:41.950
component.

02:41.950 --> 02:45.710
And in the bottom you can see noise and it will be none.

02:45.710 --> 02:52.030
So choose this basic multichannel Perlin and as soon as you gonna select that in the bottom scroll down

02:52.150 --> 02:57.350
a component just gonna attach which says Cinemachine basic multi-channel Perlin.

02:57.390 --> 03:00.030
As you can notice a noise profile.

03:00.150 --> 03:00.950
It will be done.

03:00.950 --> 03:05.510
So just click on the settings icon in the right side or this cog icon.

03:05.550 --> 03:09.270
Then go over to presets and you need to choose this 66.

03:09.390 --> 03:14.590
And as soon as you're going to do that and then you're going to get this amplitude gain value.

03:14.590 --> 03:17.390
And basically the camera just gonna start shaking.

03:17.430 --> 03:21.070
If we set this amplitude gain with some numbers.

03:21.070 --> 03:23.070
And we also need to set back to zero.

03:23.070 --> 03:26.070
So it's not gonna shake our camera at all.

03:26.070 --> 03:32.070
So what we need we need a reference of this cinemachine camera component camera component or basically

03:32.070 --> 03:33.390
this Cinemachine camera.

03:33.590 --> 03:39.710
And after that we can access this component and we can just access this parameter and we can set with

03:39.710 --> 03:40.990
some numbers.

03:40.990 --> 03:43.670
So let's create a game object for that.

03:43.670 --> 03:48.030
Or we can simply select our Cinemachine camera GameObject in the hierarchy.

03:48.230 --> 03:49.510
Then go over to Inspector.

03:49.510 --> 03:52.430
Click on Add Component Add component.

03:52.430 --> 03:55.110
So just click there, then New script.

03:55.150 --> 04:00.470
Name the script whatever you like, something like Camera Shake and then click on this Create an add

04:00.510 --> 04:02.630
button in the bottom you can notice.

04:02.630 --> 04:08.230
So I hope you get the idea that how you can do it so or else what you can do, you can just move over

04:08.230 --> 04:14.230
to your project app assets and then script folder, right click there, create, then Monobehaviour

04:14.230 --> 04:14.630
script.

04:14.670 --> 04:20.110
And you can name that script to something like camera shake and attach that script to this Cinemachine

04:20.110 --> 04:22.350
camera camera, game object.

04:22.510 --> 04:26.430
Or you can just create a separate GameObject in order to make that.

04:26.750 --> 04:31.630
So as you can notice right over here, I already have a camera shake script.

04:31.630 --> 04:33.270
I already created that.

04:33.270 --> 04:36.110
So I'm going to choose my Cinemachine camera in the hierarchy.

04:36.230 --> 04:42.070
And let's choose that camera shake script and drag it over to this add component section in the inspector,

04:42.110 --> 04:48.230
or else you can just create a separate GameObject and you can just attach that script to that GameObject.

04:48.230 --> 04:50.030
It's basically up to you.

04:50.270 --> 04:54.950
And now we're gonna open up our Camera Shake script by double clicking on it.

04:54.950 --> 04:57.750
So what we need we need our Cinemachine.

04:58.350 --> 05:03.620
So before we get the reference of this Cinemachine camera, we need to use this namespace.

05:03.620 --> 05:09.780
So whenever we working with Cinemachine camera, we need to move over to top of our class and we need

05:09.780 --> 05:11.220
to include this namespace.

05:11.220 --> 05:19.620
It's called using a using unity dot unity dot Cinemachine as Unity's Cinemachine.

05:19.620 --> 05:27.300
And if you're using older version of unity, then you have to use using Cinemachine.

05:27.620 --> 05:31.100
I guess like that, but in new we have to use this.

05:31.140 --> 05:34.140
It's called basically we need to include this namespace.

05:34.140 --> 05:37.100
It's called using unity dot Cinemachine.

05:37.100 --> 05:38.540
So make sure you do that.

05:38.740 --> 05:41.660
And now what we're going to do we're going to remove this start function.

05:41.660 --> 05:44.420
Or we can leave that to grab the reference.

05:44.420 --> 05:49.780
I'm not gonna grab the reference in the start of the game or with this start function I'm just gonna

05:49.820 --> 05:51.140
grab a manually.

05:51.140 --> 05:54.140
So that's why I'm gonna remove this start function.

05:54.380 --> 05:55.140
And we're gonna.

05:55.220 --> 05:59.660
So we need a reference of this cinemachine camera basically this one.

05:59.660 --> 06:06.740
So after that we can just access this cinemachine basic multi-channel component and we can set the amplitude

06:06.740 --> 06:07.300
value.

06:07.540 --> 06:12.940
So let's go to our script first and let's grab the reference of the camera first which is Cinemachine

06:12.940 --> 06:13.460
camera.

06:13.460 --> 06:14.860
So let's make it public.

06:15.180 --> 06:19.580
So let's make a marked as serialized field instead of doing that.

06:19.580 --> 06:23.620
So our code is just going to be a little bit clean private.

06:23.620 --> 06:25.500
And this will be Cinemachine camera.

06:25.500 --> 06:28.140
So we're going to type Cinemachine camera the component.

06:28.180 --> 06:32.300
Sorry the GameObject are we looking for is Cinemachine camera.

06:32.660 --> 06:35.500
And we can call this one Cinemachine camera.

06:35.700 --> 06:39.820
Or we shortly let's call it cam for camera.

06:40.060 --> 06:45.460
And now we're going to press down Ctrl S in order to save our script and then move over to unity.

06:45.460 --> 06:51.220
So make sure as soon as your script just gonna compile, take your Cinemachine camera and drag it over

06:51.220 --> 06:52.220
to that slot.

06:52.220 --> 06:53.700
So we will have the reference.

06:53.700 --> 06:59.970
And after that, we can set the amplitude gain to any value that we would like to go with.

06:59.970 --> 07:06.250
So just wait a moment and once our compilation is done, we're just gonna select our cinemachine camera

07:06.250 --> 07:09.850
and we're gonna drag it over to our cam slot.

07:10.090 --> 07:18.770
And now we can notice that as soon as our camera camera script compiles, we can see came and it says

07:18.770 --> 07:20.210
none Cinemachine camera.

07:20.210 --> 07:25.890
So we're going to take our Cinemachine camera from here and drag it over to that slot.

07:25.890 --> 07:30.450
Or you can simply select the game object and then drag it over to the slot.

07:30.450 --> 07:32.250
And it's going to do the same thing.

07:32.290 --> 07:38.090
Basically, you need to take your Cinemachine camera and drag it over to that cam slot or into that

07:38.090 --> 07:40.410
variable that we created.

07:40.410 --> 07:44.770
And now we have the reference as you can notice, and we are ready to shake it.

07:44.770 --> 07:48.410
So we're going to open up our camera shake script by double clicking on it.

07:48.410 --> 07:51.170
And let's make a function for shaking.

07:51.290 --> 07:53.170
And we will make this function public.

07:53.170 --> 07:59.690
Since we're going to call this function from another class or another script like once our enemy game

07:59.730 --> 08:04.610
object or player game object takes damage, then we just want to shake our camera.

08:05.050 --> 08:09.810
So that's why we're going to mark this as function as public, since we're going to call this function

08:09.810 --> 08:12.890
from another class or another script.

08:12.890 --> 08:13.690
So that's why.

08:14.090 --> 08:16.050
So we're going to mark this function public.

08:16.090 --> 08:18.090
And for function we're going to type void.

08:18.090 --> 08:19.890
And we have to name the function.

08:19.890 --> 08:21.730
So I'm going to call it something like shake.

08:21.730 --> 08:24.530
And let's make first bracket and some curly brackets.

08:24.730 --> 08:29.690
And this function over here as a first argument it's going to take the duration of the shake.

08:29.890 --> 08:33.090
And later on we're going to replace with some number.

08:33.410 --> 08:41.010
Uh so let's create a variable in the top of our uh class to just keep track of when we started shaking.

08:41.010 --> 08:45.330
So what we're going to do, we're going to create a private and this will be float.

08:45.330 --> 08:48.930
And we can call this one something like a start time.

08:48.930 --> 08:51.330
So let's call it start time.

08:51.650 --> 08:54.450
And we're going to close that off with a semicolon.

08:54.650 --> 08:57.370
And in the end what we're going to do now.

08:57.850 --> 09:00.890
So this shape function just going to take two arguments.

09:00.930 --> 09:03.090
First thing it's going to take the duration.

09:03.090 --> 09:06.890
And the second thing it's going to be the intensity with how much intense.

09:06.930 --> 09:09.170
We just want to shake our camera.

09:09.370 --> 09:15.970
And we created this start time variable up here to just keep track of when we started shaking our camera.

09:16.210 --> 09:17.570
So basically that is the thing.

09:17.570 --> 09:18.930
I hope you get the idea.

09:19.130 --> 09:22.210
So the first thing float, this will be float.

09:22.210 --> 09:27.890
And we can call this one duration or shake time something like that and start time.

09:27.930 --> 09:32.210
Sorry I'm going to call this as shake time instead of calling start time.

09:32.210 --> 09:34.370
So I'm going to call it Shake time.

09:34.690 --> 09:41.170
And second thing this shake function just going to take the intensity or how much intense we want to

09:41.170 --> 09:42.930
shake our camera intensely.

09:42.930 --> 09:43.530
We want.

09:43.570 --> 09:45.650
And that will be also a float.

09:45.650 --> 09:49.570
And we can call this one intensity intensity.

09:49.770 --> 09:56.330
So and later on we're going to replace this duration and this intensity with some number something like

09:56.370 --> 09:57.170
we duration.

09:57.170 --> 10:00.680
We can just set it to something around 0.2 second.

10:00.720 --> 10:02.960
We just want to check and intensity.

10:03.000 --> 10:04.800
We can just pass something like two.

10:04.840 --> 10:08.200
So we can set the amplitude gain to something like two three.

10:08.320 --> 10:10.680
So that's why we just given arguments.

10:10.680 --> 10:15.920
And later on when we're going to call this check function, we're going to replace this duration and

10:15.920 --> 10:18.240
the intensity with real numbers.

10:18.440 --> 10:22.880
And that will be float like 0.1 or 1, two, three, four like that.

10:22.880 --> 10:29.880
And now so before so when we're going to call the seq function, we're going to check our check time.

10:29.880 --> 10:34.240
And we're going to set equal to our duration a duration.

10:34.240 --> 10:36.240
And let's close that up with semicolon.

10:36.680 --> 10:41.480
So what we have done over here we just set our check time equal to duration.

10:41.520 --> 10:46.080
So we just created this time variable to just keep track of when we started checking.

10:46.280 --> 10:50.800
So let's suppose uh as a duration we pass something like 0.1.

10:50.800 --> 10:55.040
So this this duration right over here it's going to be 0.1.

10:55.040 --> 10:58.640
So that's why this check time over here it's going to be 0.1.

10:58.640 --> 10:59.120
Why?

10:59.160 --> 11:05.600
Because we directly setting it as you can see, and we just set equal to this set equal to our duration

11:06.120 --> 11:09.600
to just keep track of when we started shaking our camera.

11:10.040 --> 11:11.800
So that's is the thing.

11:12.000 --> 11:14.320
And now what we need, we need a reference.

11:14.360 --> 11:20.680
Uh, basically we need to get this animation basic multi-channel multi-channel perlin component.

11:20.720 --> 11:23.720
We have the Cinemachine camera and reference.

11:23.720 --> 11:28.360
So we're going to get the component which is Cinemachine basic multi-channel Perlin.

11:28.360 --> 11:30.000
So let's get the component.

11:30.000 --> 11:32.160
So the component we're looking for.

11:32.160 --> 11:33.600
So which is Cinemachine.

11:34.080 --> 11:36.680
So what we're going to do firstly we will go to cam.

11:36.840 --> 11:37.160
Cam.

11:37.160 --> 11:40.400
Basically we're just going over to that Cinemachine camera.

11:40.400 --> 11:45.000
And now we're going to use this dot get component uh dot get component.

11:45.000 --> 11:49.280
And inside this arrows it's going to take the component that we want to get.

11:49.280 --> 11:53.320
So we want to get that basic multi-channel and perlin as you seen.

11:53.320 --> 11:58.760
So I'm going to pass inside this arrow which is basic multi cinemachine basic multi-channel burning

11:58.760 --> 12:02.200
and then make this first bracket and then close that up with semicolon.

12:02.200 --> 12:04.960
So now we have the reference as you can notice.

12:04.960 --> 12:09.680
And now what we're going to do, we're going to store this cinemachine basic multi-channel Berlin into

12:09.720 --> 12:13.360
another cinemachine basic multi-channel Berlin variable.

12:13.360 --> 12:19.200
Or you can simply say in a container a container and the container should be type Cinemachine basic

12:19.200 --> 12:20.360
multi-channel Berlin.

12:20.360 --> 12:20.800
Why?

12:21.000 --> 12:26.040
Because this we're just getting the component Cinemachine basic multi-channel Berlin.

12:26.040 --> 12:31.960
So that's why we need to put it in a variable, or in a container or a parameter with the same type.

12:31.960 --> 12:34.800
And we have to name the container or the variable.

12:34.960 --> 12:37.240
And we're going to call it Berlin simply.

12:37.240 --> 12:39.320
And let's set equal to this.

12:39.320 --> 12:41.960
So firstly we're going over to Cinemachine camera.

12:42.000 --> 12:44.240
As you can see name came.

12:44.280 --> 12:47.240
Then we just using this dot get component.

12:47.240 --> 12:51.160
And the component we're looking for is Cinemachine basic multi-channel Berlin.

12:51.160 --> 12:57.000
As you can notice right over here basically we're just going over to this animation camera uh camera

12:57.190 --> 12:58.270
component first.

12:58.550 --> 13:01.310
Or you can simply say Cinemachine camera.

13:01.350 --> 13:02.110
Camera.

13:02.110 --> 13:05.430
And after that we just taking this cinemachine basic multi-channel.

13:05.470 --> 13:07.070
Berlin component.

13:07.070 --> 13:12.030
And we storing that into this Berlin as you can see right over here.

13:12.030 --> 13:17.710
So basically we're just taking that and basically this one and we're storing right over here into this

13:17.710 --> 13:18.230
Berlin.

13:18.270 --> 13:21.670
Now we have the uh having that component.

13:21.670 --> 13:23.870
And now we can access the parameter.

13:23.870 --> 13:27.750
So what we're going to do now we're going to do this Berlin Dot.

13:28.390 --> 13:31.230
And we want to access the amplitude gain.

13:31.270 --> 13:35.870
Basically we want to access this amplitude gain, this amplitude gain.

13:35.910 --> 13:37.950
As you can notice in the inspector.

13:37.950 --> 13:44.790
And we're going to set this amplitude gain equal to our intensity or with how much intensity we want

13:44.790 --> 13:46.350
to shake our camera.

13:46.350 --> 13:49.470
So that's why we're going to access Perlin dot Perlin.

13:49.470 --> 13:51.710
And we're going to access the amplitude gain.

13:51.710 --> 13:54.910
And we're going to set equal to our intensity.

13:54.910 --> 13:57.310
And now we're going to close that off with semicolon.

13:57.310 --> 13:58.630
So firstly, what are we doing?

13:58.630 --> 14:04.550
Firstly going over to this cinemachine camera, then getting this cinemachine basic multi-channel Berlin

14:04.550 --> 14:10.830
component, and we storing this one into this cinemachine basic multi-channel pardon or into this Berlin,

14:10.830 --> 14:12.950
as you can see right over here.

14:13.110 --> 14:16.870
And after that we just go accessing this amplitude gain.

14:16.910 --> 14:18.910
As you can notice right over here.

14:19.310 --> 14:24.910
Firstly going over to this cinemachine basic multi-channel Berlin and then accessing this amplitude

14:24.910 --> 14:25.350
gain.

14:25.350 --> 14:30.310
And we setting this amplitude gain equal to our intensity as you can notice.

14:30.310 --> 14:34.750
So firstly we're going to Berlin and then we access the amplitude gain.

14:34.750 --> 14:37.070
And we setting equal to intensity.

14:37.070 --> 14:39.510
As you can notice right over here.

14:39.990 --> 14:41.710
So I hope you get the idea.

14:41.710 --> 14:44.630
And let's suppose as an intensity you pass two.

14:44.670 --> 14:47.670
So this intensity right over here it's going to be two.

14:47.710 --> 14:49.270
So this amplitude gain.

14:49.270 --> 14:51.990
So Berlin dot amplitude gain just going to be two.

14:52.030 --> 14:56.070
As you can notice because we directly setting it as you can see.

14:56.230 --> 15:01.660
So this amplitude gain is just going to be true when we're going to set basically when we're going to

15:01.660 --> 15:04.660
replace this intensity with our real numbers.

15:04.820 --> 15:07.620
And now we have done we have done these things.

15:07.620 --> 15:11.020
And we can simply press down control s to save our script.

15:11.020 --> 15:12.900
And now we need to call this function.

15:13.020 --> 15:15.540
So I'm going to press Ctrl S to save my script.

15:15.540 --> 15:17.220
And let's move over to unity.

15:21.340 --> 15:22.940
So it's going to be fine.

15:22.940 --> 15:24.980
And we need to call this save function.

15:24.980 --> 15:30.780
But when we need to call this function once our player game object or enemy game object just going to

15:30.780 --> 15:32.860
take damage or just going to attack.

15:33.020 --> 15:35.580
So uh, then we're going to call that.

15:35.580 --> 15:39.900
So I'm going to call it once our player game object gonna take damage.

15:39.900 --> 15:42.940
So we will select our player GameObject in the hierarchy.

15:42.940 --> 15:46.020
And let's open up the player script by double clicking on it.

15:46.020 --> 15:50.340
And let's move over to Takedamage function basically where we're taking damage.

15:50.340 --> 15:56.700
So if we scroll down and move over to take damage function, and we made it in the bottom right over

15:56.700 --> 15:58.420
here, as you can notice.

15:58.420 --> 16:02.820
And we just subtracting our health basically with this damage amount.

16:02.820 --> 16:05.260
So we also want to check our camera.

16:05.260 --> 16:09.860
So basically what we need to do we basically need to go over to that camera shake script.

16:09.860 --> 16:12.060
And then we need to call the shake function.

16:12.060 --> 16:14.700
And we do know what that shake function is going to do.

16:14.740 --> 16:18.140
It's gonna shake our camera with, uh, intensity.

16:18.140 --> 16:21.420
So firstly we're going to use this find any object by type.

16:21.780 --> 16:21.940
Uh.

16:21.940 --> 16:24.460
So use this and then make this arrows.

16:24.460 --> 16:30.380
And inside this arrows you need to pass the script name script name that you're looking for or what

16:30.380 --> 16:31.460
you're looking for.

16:31.460 --> 16:34.940
So we're looking for our camera shake script as we created.

16:34.940 --> 16:38.380
So that's why in this arrows we're going to pass this camera shake.

16:38.420 --> 16:38.940
Sorry.

16:39.580 --> 16:43.780
Uh we're going to pass this camera shake camera shake.

16:43.820 --> 16:45.780
And we need to make this brackets.

16:45.780 --> 16:49.900
And after making brackets, we can just access anything that we like.

16:49.900 --> 16:51.700
So we want to call the shake function.

16:51.700 --> 16:55.660
So that's why we're going to type this dot and we're going to call the shake function.

16:55.660 --> 17:00.260
So let's type this check and let's make first bracket and then close that up with semicolon.

17:00.260 --> 17:06.180
And now this check function as a as a first argument it's going to take the duration uh with how much

17:06.180 --> 17:06.740
duration.

17:06.740 --> 17:07.940
We just want to check.

17:07.940 --> 17:13.420
So I want to check my camera for a little moment or few seconds less than few seconds.

17:13.420 --> 17:16.140
So that's why I'm going to pass something like 0.15.

17:16.580 --> 17:22.340
And the second thing, it's going to take the intensity, uh, with how much intensity or amplitude

17:22.340 --> 17:22.780
gain.

17:22.820 --> 17:24.740
We just want to set width.

17:24.740 --> 17:27.500
So I'm gonna set with something around two f.

17:27.700 --> 17:29.980
So now we're going to press down ctrl s.

17:30.100 --> 17:35.500
So what we're doing once our player game object takes damage then we're just going over to that camera

17:35.500 --> 17:38.140
shake script and then calling the save function.

17:38.140 --> 17:41.660
And as a first argument we just pass 0.15.

17:42.100 --> 17:45.060
And as an intensity we just pass to F.

17:45.060 --> 17:47.220
So the amplitude gain is just going to be two.

17:47.260 --> 17:48.900
And let me explain one more time.

17:48.900 --> 17:50.460
So just wait a moment.

17:50.460 --> 17:55.500
And once our compilation is done we can just go ahead and check that out.

17:57.050 --> 17:57.970
So now.

18:00.930 --> 18:02.970
So now let me explain.

18:02.970 --> 18:09.930
So if I select my cinemachine camera camera in the hierarchy then go over to camera script in Inspector.

18:09.930 --> 18:15.290
So basically we just go going over to this class as you can notice right over here.

18:15.290 --> 18:17.290
And then we're calling this check function.

18:17.290 --> 18:20.290
And we do know what check function just gonna do as.

18:20.330 --> 18:23.010
So as a duration we pass 0.15.

18:23.210 --> 18:25.010
So this is going to be 0.15.

18:25.450 --> 18:28.570
So so this much of time we want to check.

18:28.610 --> 18:30.850
And the second thing we pass intensity.

18:30.850 --> 18:34.010
And as you seen as in intensity we pass two.

18:34.050 --> 18:37.050
So this intensity right over here it's going to be two.

18:37.090 --> 18:43.090
So that's why amplitude gain just going to be two right away means our camera just gonna check with

18:43.130 --> 18:46.250
two a unit of uh with two unit.

18:46.250 --> 18:49.810
So now let's move over to script sorry unity editor.

18:50.050 --> 18:54.250
And let's click on this play button in the top in order to play our game.

18:54.250 --> 18:57.890
So as soon as our player just gonna take damage, it will.

18:58.090 --> 19:02.250
The camera just gonna start shaking and you will see that.

19:03.250 --> 19:04.690
Uh, so just wait a moment.

19:05.330 --> 19:10.690
And if we get closer to this enemy, uh, one game object and enemy.

19:10.690 --> 19:11.930
Just gonna try to shoot.

19:11.930 --> 19:17.770
As you can see, indeed, the camera is shaking, and it's shaking, uh, for longer time.

19:18.010 --> 19:21.570
Uh, so we also need to set back this amplitude gain to zero.

19:21.690 --> 19:27.970
So as you can notice, inside this cinemachine basic multi-channel Perlin component in the inspector,

19:27.970 --> 19:30.290
we can see amplitude gain is two.

19:30.330 --> 19:32.530
So we also need to set back to zero.

19:32.850 --> 19:34.930
So the camera will stop shaking.

19:34.930 --> 19:38.810
So if we set back to zero as you can see camera stop shaking.

19:38.810 --> 19:43.930
So we also need to set back to zero this amplitude gain uh amplitude gain.

19:43.930 --> 19:45.250
So we're gonna get out of play mode.

19:45.250 --> 19:48.490
But when we shoot once the duration is over.

19:48.490 --> 19:54.730
So that's why we just created that parameter, which is duration, uh, inside our shake function.

19:54.730 --> 19:56.650
So we will move over to script.

19:56.650 --> 19:59.570
And we created this time as you can notice.

19:59.570 --> 19:59.970
So.

20:00.290 --> 20:03.450
So if we call this function it's going to take our camera.

20:03.450 --> 20:06.130
And the reason we pass .158.

20:06.290 --> 20:10.970
So this time right over here it's going to be .15 F.

20:11.090 --> 20:16.890
So this is going to be a bigger than zero basically greater than zero number.

20:16.890 --> 20:19.290
So what we would do what we going to do.

20:19.290 --> 20:22.130
Now we're going to move over to this update function.

20:22.130 --> 20:24.690
And update function runs every single frame.

20:24.690 --> 20:26.370
And over here we're going to check.

20:26.370 --> 20:28.570
So we're going to use this if condition.

20:28.570 --> 20:31.330
Let's make first bracket and some curly brackets.

20:31.330 --> 20:33.290
And what we want to check over here.

20:33.290 --> 20:38.730
We basically want to check if our check time if our check time is greater than zero.

20:38.770 --> 20:44.770
If if if it's greater than zero f then we need to subtract some amount from this check time.

20:45.050 --> 20:50.330
So we do know that once we're going to call this check time check function, this check time just going

20:50.330 --> 20:52.090
to be duration and duration.

20:52.090 --> 20:54.450
We pass .11 f.

20:54.450 --> 20:58.760
So this time over here, it's going to be 0.158.

20:58.960 --> 21:00.040
And so that's why.

21:00.080 --> 21:02.640
And we do know that .15.

21:02.640 --> 21:06.320
So this time is say time is 0.15.

21:06.320 --> 21:09.800
So and we do know that 0.15 is greater than zero.

21:09.840 --> 21:11.720
Basically it's greater than zero.

21:11.720 --> 21:18.920
So so in that moment what we just want to do, we just want to subtract from this time as some amount

21:18.960 --> 21:23.600
every single frame until and unless this time it hits zero.

21:23.600 --> 21:30.240
And when it hits when it hits zero, then we will stop shaking our camera.

21:30.480 --> 21:36.680
So what we're going to do now, we're going to subtract from this time minus equal minus equal times

21:36.680 --> 21:38.880
delta time and times delta time.

21:38.880 --> 21:42.280
We do know basically this means change in frame rate.

21:42.280 --> 21:44.120
So this time set time.

21:44.120 --> 21:46.760
So once we're going to call this a shake function.

21:46.760 --> 21:49.440
So this set time just going to be 0.15.

21:49.480 --> 22:01.120
Or with this much of duration and duration we pass 0.15 as using, so this time becoming 1.5 sorry 0.15.

22:01.120 --> 22:07.920
So and we do know that 0.15 is greater than 0F0F, then what we're doing, we just subtracting from

22:07.920 --> 22:13.680
this check time every single frame because we're doing inside this update function as you can notice.

22:13.680 --> 22:19.560
So somehow sometime this check time basically after some amount of time, this check time just gonna

22:19.560 --> 22:20.000
be zero.

22:20.000 --> 22:23.680
Because what we're doing we just subtracting every single frame.

22:23.680 --> 22:28.320
So sometimes uh, at somewhere this time it's just going to hit zero.

22:28.480 --> 22:32.920
And when it, when it's gonna hit zero then we will stop checking.

22:32.920 --> 22:37.440
So we also want to check if so we're going to use this if condition.

22:37.440 --> 22:40.200
Let's make first bracket and some curly brackets.

22:40.200 --> 22:42.160
And what we want to check over here.

22:42.320 --> 22:47.320
So we want to check if our check time is now already zero or lesser than zero.

22:47.320 --> 22:52.880
And we do know that at some point this check time just going to hit zero because we every single frame,

22:52.880 --> 22:58.030
as you can notice right over here we're just subtracting some amount from this time.

22:58.030 --> 23:01.830
So this time I'm just going to hit zero after some period of time.

23:01.830 --> 23:06.430
So we will check if our set time is now lesser than or equal to zero.

23:06.870 --> 23:10.270
If that is the case means duration is over.

23:10.310 --> 23:14.390
Basically that time period is over and now we need to stop checking.

23:14.390 --> 23:17.950
Basically, we need to set that amplitude gain parameter to zero.

23:18.110 --> 23:23.070
And as you saw, if we set back this parameter to zero it's going to stop checking.

23:23.070 --> 23:28.230
So firstly we need we need to get this animation basic multi-channel Perlin component.

23:28.230 --> 23:31.110
And after that we can access this amplitude gain.

23:31.110 --> 23:32.910
And we're gonna set back to zero.

23:33.110 --> 23:37.590
So now what we're going to do we're going to copy this line of code from here by Ctrl C.

23:37.750 --> 23:41.190
And we're gonna paste it by Ctrl V, basically what we're doing.

23:41.190 --> 23:44.430
We just taking that cinemachine basic multi-channel perlin.

23:44.470 --> 23:49.030
Basically this one, this animation basic multi-channel Perlin component.

23:49.030 --> 23:55.950
And we storing into this Perlin this variable or in this container as you can see, which is Cinemachine

23:55.950 --> 23:57.550
basic multi-channel Perlin.

23:57.550 --> 23:59.670
And we're storing inside this Perlin.

23:59.670 --> 24:02.150
And then we accessing the amplitude gain.

24:02.150 --> 24:05.710
Now we're gonna not gonna set equal to intensity.

24:05.710 --> 24:08.870
Instead we're gonna set it to set it to zero.

24:08.910 --> 24:10.230
If as you can see.

24:10.710 --> 24:14.070
So firstly firstly we subtracting from this set time.

24:14.070 --> 24:19.670
And once our set time hit zero and we do know it's somehow it's just going to hit zero.

24:19.670 --> 24:25.270
And if it's hit zero as you can see, if it's less than or equal to zero, then we're just going over

24:25.270 --> 24:30.830
to Cinemachine basic multi-channel Perlin component and then accessing the amplitude gain basically

24:30.830 --> 24:33.390
this one and we setting it to zero.

24:33.390 --> 24:35.710
As you can notice right over here.

24:35.950 --> 24:42.870
And we now if we set back amplitude gain to zero, we do know that our camera just gonna stop shaking.

24:42.870 --> 24:44.030
And now what we have to do.

24:44.070 --> 24:48.750
We're going to press down Ctrl s on our keyboard in order to save our script.

24:49.550 --> 24:51.710
But before I do I'm just gonna add in.

24:51.790 --> 24:54.910
So this parameter that we created right over here.

24:54.950 --> 24:58.070
Take time to just keep track of when we started shaking.

24:58.230 --> 25:00.630
And you you can use the start function.

25:00.630 --> 25:04.750
And in this start of the game you can just set the shake time something like zero.

25:04.910 --> 25:11.070
And whenever we're going to call this check function we do know that a then at that moment this set

25:11.110 --> 25:12.390
time not going to be zero.

25:12.390 --> 25:20.270
It's going to be with duration or uh, or what amount we just pass as a first argument with this duration.

25:20.310 --> 25:21.830
Basically that is the thing.

25:21.830 --> 25:23.470
So I hope you get the idea.

25:23.470 --> 25:26.750
And now we're going to press down Ctrl s to save our script.

25:26.750 --> 25:32.270
So we're just subtracting from this set time minus equal time dot delta time as you can see.

25:32.470 --> 25:35.830
So at some point this time just going to hit zero.

25:35.830 --> 25:42.110
And once it hits zero then we just uh going over to Cinemachine basic multi-channel bonding component

25:42.110 --> 25:44.270
and accessing the amplitude gain.

25:44.270 --> 25:46.070
And we setting equal to zero.

25:46.430 --> 25:51.950
And we do know once we're gonna set it back to zero if our camera will stop shaking.

25:51.950 --> 25:54.940
So just wait a moment to compile our script.

25:55.060 --> 26:00.340
And once the compilation is done, we can just go ahead and then play.

26:00.420 --> 26:03.860
Let's click on this play button in the top in order to play our game.

26:04.020 --> 26:10.220
And you will notice that our camera just gonna shake with that much of duration as we pass as first

26:10.220 --> 26:10.940
argument.

26:10.940 --> 26:15.380
And the second thing just gonna be the intensity and intensity we pass to.

26:15.420 --> 26:17.580
So amplitude just just gonna be to.

26:17.620 --> 26:19.500
And basically we do know that.

26:19.500 --> 26:25.340
So after the the duration is over, our camera just going to stop shaking.

26:25.380 --> 26:33.420
And indeed we can notice that camera is stop shaking once our player uh player uh once the duration

26:33.420 --> 26:36.220
is over or that shake time is zero.

26:36.220 --> 26:42.980
So if so, if I get out of play mode and then select the cinemachine camera so we're not able to notice

26:42.980 --> 26:44.580
our private parameter.

26:44.580 --> 26:47.100
And we do know that how we can access that.

26:47.100 --> 26:49.740
For that we will go to Inspector in the top right.

26:49.740 --> 26:53.220
We're going to click on this three dot and let's choose this debug.

26:53.420 --> 26:56.740
And we can notice by now the set time is zero by default.

26:56.900 --> 27:04.100
And so once we start our game and take damage from this enemy one game object, you will see this check

27:04.140 --> 27:05.740
time just going to be 0.15.

27:05.780 --> 27:09.140
Because as a depression we pass 0.15.

27:09.180 --> 27:14.500
As you seen inside that script inside our player uh, C-sharp class.

27:14.500 --> 27:16.220
So you will see.

27:16.220 --> 27:22.700
So let's get closer to this enemy one game object and we can see indeed, uh, the same time just becoming

27:22.700 --> 27:23.700
some numbers.

27:23.700 --> 27:27.140
And we can see the check time is now -0.0.

27:27.180 --> 27:28.780
Uh, basically it's zero.

27:29.060 --> 27:34.500
So if it's zero, then what we're doing, we just say am accessing the amplitude gain, and then we

27:34.500 --> 27:36.020
just setting equal to zero.

27:36.060 --> 27:38.580
As you can notice right over here.

27:38.580 --> 27:40.300
So I hope you get the idea.

27:40.300 --> 27:42.100
And we're going to get out of play mode.

27:42.100 --> 27:49.340
And we also want to call that function, uh, once our uh, this enemy one enemy, one game object takes

27:49.340 --> 27:50.020
damage.

27:50.020 --> 27:53.260
But before I do, I just want to go over to normal mode.

27:53.300 --> 27:57.060
To do that, let's go over to Inspector Top right.

27:57.060 --> 28:00.020
Let's click on it and let's click on this normal.

28:00.020 --> 28:05.420
And we're going to open up our anime one script as well as anime two script in order to call the function

28:05.420 --> 28:06.220
which is sick.

28:06.380 --> 28:11.540
And we do know that check function is just going to check our camera as an image in camera.

28:11.540 --> 28:13.900
So I'm going to select my anime one game object.

28:13.900 --> 28:18.900
Let's go over to Inspector and let's open up this anime one script by double clicking on it.

28:19.420 --> 28:20.940
And let's open that up.

28:21.260 --> 28:22.380
And over here.

28:22.380 --> 28:25.780
As you can notice, our anime is taking damage.

28:25.780 --> 28:27.140
So we're going to call the function.

28:27.140 --> 28:28.500
So let's call it here.

28:29.020 --> 28:31.140
And let's call the function here.

28:32.340 --> 28:37.580
And to call the function we're going to use find or find any object by type.

28:37.780 --> 28:40.660
So we're going to use this find any object by type.

28:40.700 --> 28:42.260
And then make this arrows.

28:42.260 --> 28:46.580
And inside these arrows you need to pass the script name that you're looking for.

28:46.580 --> 28:49.220
So we're looking for our camera check script.

28:49.220 --> 28:52.340
So let's go there and let's make this first bracket.

28:52.340 --> 28:54.330
And then we're going to call the save function.

28:54.330 --> 28:55.090
So let's call it.

28:55.090 --> 28:58.010
So let's type this dot and then check function.

28:58.010 --> 28:59.370
And let's make first bracket.

28:59.370 --> 29:01.370
And then close that up with semicolon.

29:01.530 --> 29:07.770
And this function as you can notice as a first argument it's going to take the duration or the time

29:07.810 --> 29:12.690
frame that we are with how much amount of time we want to check our camera.

29:12.930 --> 29:19.690
So I'm going to give a pretty smaller number, something like .0.12, something like that.

29:19.690 --> 29:24.130
And the second thing comma, it's going to take the intensity or the amplitude gain.

29:24.170 --> 29:30.410
You can simply say so I want to set the intensity something around a little bit higher, something like

29:30.410 --> 29:31.170
four F.

29:31.450 --> 29:33.850
And now as you can see it's fine.

29:33.850 --> 29:38.850
So whenever anyone just going to take damage, it will check our camera.

29:38.850 --> 29:43.410
With this much of duration and with this much of intensity.

29:43.450 --> 29:46.690
And now we're going to press down Ctrl S to save our script.

29:46.690 --> 29:48.570
And now let's move over to unity.

29:48.570 --> 29:50.370
And you will notice that.

29:50.730 --> 29:54.810
So as soon as this anime one just going to take damage.

29:54.810 --> 30:03.250
The camera will start shaking with that much of intensity, which we pass as our second argument and

30:03.250 --> 30:04.050
first argument.

30:04.050 --> 30:08.370
We pass our duration, so we just give arguments and we can.

30:08.370 --> 30:11.530
Just later, if I move over to my camera shake script.

30:11.530 --> 30:18.570
So we're just giving this argument and we can later on we can just place these arguments with real number.

30:18.610 --> 30:19.890
Basically that is the thing.

30:19.890 --> 30:22.250
So that's why it's taking argument.

30:22.570 --> 30:28.410
And you can just pass the argument and later on you can just replace that with real numbers.

30:28.410 --> 30:31.210
And now we're going to move over to Unity Editor.

30:31.250 --> 30:33.530
And let's click on this play button in the top.

30:33.530 --> 30:37.530
And let's attack this anime one game object.

30:37.650 --> 30:44.170
And as soon as this anime one game object start taking damage, it will shake with that much of duration

30:44.170 --> 30:49.090
as we passed as a first argument with that, with our intensity.

30:49.370 --> 30:54.760
So let's uh, we see we can notice, our player is taking damage.

30:54.760 --> 31:01.320
And now if we attack on this enemy one game object, we can see enemy just taking damage and camera

31:01.360 --> 31:02.320
starts shaking.

31:02.480 --> 31:08.480
And after shaking a little bit or basically that much of duration camera just stop shaking.

31:08.520 --> 31:08.920
Why?

31:08.960 --> 31:14.280
Because if I select my cinemachine camera in the hierarchy, then go over to Inspector, then Cinemachine

31:14.280 --> 31:16.280
basic multi-channel Perlin component.

31:16.280 --> 31:18.800
In the bottom we can see amplitude gain.

31:18.800 --> 31:23.360
We just set back to zero, but as soon as we attack we just set to four.

31:23.360 --> 31:29.000
And after setting four and once the duration is over, we can see it's became zero.

31:29.120 --> 31:34.640
So I hope you get the idea that how you can do it, or how you can just shake your camera and you can

31:34.640 --> 31:37.320
call the shake function wherever you need.

31:37.320 --> 31:42.760
So I'm going to get out of play mode so you can call the function in inside that enemy to game object

31:42.760 --> 31:49.520
as well, where enemy two GameObject just taking damage so you can call the function there as well.

31:49.600 --> 31:52.600
So I hope you get the idea that how you can do this.
