WEBVTT

00:00.020 --> 00:00.500
Hello guys.

00:00.500 --> 00:01.430
Welcome to the video.

00:01.430 --> 00:04.250
In this one I want to show you how to make camera shake.

00:04.250 --> 00:08.420
It will improve the feedback of the game very much and I like to use it a lot.

00:08.420 --> 00:09.500
So let's do it.

00:09.500 --> 00:15.950
It's pretty easy to set up and before we do that, let's do a bit of like general cleanup in the hierarchy.

00:15.950 --> 00:19.760
So for the main camera I want to make a parent.

00:19.760 --> 00:21.470
It's going to be camera.

00:22.510 --> 00:23.320
Manager.

00:25.610 --> 00:27.860
And for these two, let's make a parent.

00:30.230 --> 00:34.310
Level camera just like that, and I'm going to place it.

00:36.250 --> 00:37.210
Wait a second.

00:38.910 --> 00:40.470
Going to place it like that.

00:40.800 --> 00:41.340
Okay.

00:41.340 --> 00:42.180
Very nice.

00:42.180 --> 00:49.170
Now let's go to scripts and let's make a script camera manager.

00:50.530 --> 00:53.860
Then we're going to take the camera manager and put the script on.

00:56.630 --> 00:57.560
Camera manager.

00:57.560 --> 00:58.370
Okay.

00:58.850 --> 01:01.700
It is very easy to make a screen shake.

01:01.700 --> 01:05.720
We just need to add component of um.

01:07.000 --> 01:11.920
Impulse source, Cinemachine impulse source like that.

01:11.920 --> 01:16.180
And we need to add Cinemachine impulse listener on the camera.

01:16.540 --> 01:18.610
So here we're going to go to camera.

01:20.350 --> 01:25.420
And we're going to add the extension of Cinemachine impulse listener.

01:25.600 --> 01:26.620
Let's click it.

01:26.620 --> 01:29.950
So now this camera listens to the impulses we have.

01:29.950 --> 01:32.410
And over here we have a source of the impulse.

01:32.410 --> 01:37.150
And we just need to get this component and type dot generate impulse.

01:37.150 --> 01:38.320
Simple as that.

01:39.100 --> 01:40.900
Now let's go to camera manager.

01:41.620 --> 01:43.960
First, I want to make it work as a single tone.

01:45.820 --> 01:55.450
So I'm going to make public static camera manager instance and then awake instance equals to this.

01:55.900 --> 01:57.550
Now let's make a header.

01:57.640 --> 01:59.230
Header camera.

02:00.800 --> 02:01.610
Shake.

02:02.820 --> 02:08.010
And we're going to do centralized field private vector two shake velocity.

02:08.370 --> 02:11.580
And we need component of the source.

02:11.580 --> 02:14.250
And I don't think we need to see it in the inspector.

02:14.250 --> 02:18.150
So I'm going to just do private Cinemachine impulse source.

02:18.150 --> 02:22.620
And let's just call it impulse source.

02:23.740 --> 02:24.550
Nice.

02:24.550 --> 02:26.230
Now we need to get this component.

02:26.230 --> 02:30.910
So I'm going to do input source equals to get component of cinemachine input source.

02:30.910 --> 02:33.340
And then we need a method that will check the camera.

02:33.340 --> 02:34.690
So public void.

02:37.440 --> 02:38.850
Camera shake.

02:39.960 --> 02:43.230
In which we want to update velocity on this component.

02:43.230 --> 02:45.390
So I'm going to do impulse source.

02:46.490 --> 02:50.120
Default velocity equals to new vector.

02:50.270 --> 02:50.990
Two.

02:52.060 --> 02:52.540
Shake.

02:52.540 --> 02:53.080
Velocity.

02:53.290 --> 02:53.770
X.

02:53.770 --> 02:54.670
Shake velocity.

02:54.670 --> 02:55.360
Dot y.

02:55.780 --> 02:56.860
Very nice.

02:57.190 --> 03:02.290
And then we're going to need to do input source dot generate impulse.

03:02.410 --> 03:03.610
Simple as that.

03:04.340 --> 03:06.170
All right, let's save this.

03:06.170 --> 03:06.410
Now.

03:06.410 --> 03:08.060
Let's go to player script.

03:10.190 --> 03:16.490
We need to find this knockback method and if we do not return from a method, means we can do a screen

03:16.490 --> 03:20.870
shake and we're going to do camera manager dot instance.

03:23.800 --> 03:24.940
Camera shake.

03:25.570 --> 03:27.250
I don't like to call it camera shake.

03:27.250 --> 03:29.110
Can I call it screen shake?

03:30.180 --> 03:30.810
Okay.

03:31.740 --> 03:33.300
Screen shake.

03:36.890 --> 03:38.270
All right, this is better.

03:38.270 --> 03:39.440
Let's save this.

03:39.440 --> 03:40.490
Let's go to player.

03:40.490 --> 03:40.700
Yes.

03:40.700 --> 03:41.900
We have this method here.

03:41.900 --> 03:42.980
It's okay.

03:42.980 --> 03:45.380
Now let's go back to unity.

03:48.250 --> 03:51.100
We can define the velocity over here.

03:51.100 --> 03:55.840
And for example, I want to do 0.75 by 0.75.

03:56.350 --> 03:57.760
Let's go to play mode.

03:59.370 --> 04:05.790
And now every time I'm getting knocked back, we can see a screen shake, which is very nice, I like

04:05.790 --> 04:06.150
it.

04:07.290 --> 04:09.930
Now there are different shake modes.

04:10.710 --> 04:19.020
Uh, let me show it to you so you can go over here and change the shape of the impulse to, for example,

04:19.020 --> 04:19.920
recoil.

04:19.920 --> 04:21.660
This is how it's going to feel now.

04:22.170 --> 04:24.870
There is also explosion.

04:26.470 --> 04:28.360
Or there is a rumble.

04:29.910 --> 04:37.230
Also, you can increase the duration of this, let's say one second and it's gonna work differently.

04:37.230 --> 04:39.660
So now it's up to you how you want it to work.

04:39.660 --> 04:42.750
You just need to decide on the final filling you want to have.

04:43.230 --> 04:44.700
And there is a recoil.

04:45.210 --> 04:49.140
You just define the power and the length.

04:49.140 --> 04:52.440
You could also test for subway here with different values.

04:53.430 --> 04:54.120
Right.

04:55.060 --> 05:03.250
For example, I kind of liked how rumble feels, so I'm going to try to set it to 0.5 with a power of

05:03.250 --> 05:03.640
one.

05:03.640 --> 05:04.570
And let's see.

05:06.080 --> 05:06.560
Yet.

05:06.560 --> 05:07.280
It's not that bad.

05:07.310 --> 05:11.660
I like it, so maybe I'm going to use it all the feels like it's too strong.

05:12.200 --> 05:13.940
Maybe 0.7.

05:17.360 --> 05:17.690
Okay.

05:17.690 --> 05:18.740
I'm going to keep it.

05:18.740 --> 05:20.690
I'm going to see how I feel about it.

05:20.690 --> 05:23.540
Most likely I'm going to get back to bump.

05:24.610 --> 05:27.100
As this one is good with the lower value.

05:28.400 --> 05:31.730
Yeah, but again, you can see it's all up to what you like.

05:31.760 --> 05:33.770
You know, I'm going to keep ramble for now.

05:33.770 --> 05:36.080
Let's see how it feels during the testing.

05:36.470 --> 05:36.770
All right.

05:36.770 --> 05:40.220
So I'm going to, uh, go off the play mode.

05:40.220 --> 05:41.990
Let's change it to ramble.

05:42.590 --> 05:46.850
Let's do 0.5 and we define shake velocity over here.

05:46.850 --> 05:49.550
So 75 by 75 looks good to me.

05:49.550 --> 05:52.730
I only want to apply the knockback direction.

05:52.730 --> 05:56.600
So camera moves into the direction we were knocked.

05:56.930 --> 05:58.730
Uh let's go to camera manager.

05:58.730 --> 06:01.310
And over here we're going to pass it.

06:02.270 --> 06:03.860
Uh, shake direction.

06:05.300 --> 06:07.160
And then on the player.

06:09.440 --> 06:14.000
And then over here we're going to multiply x by the shake direction.

06:14.990 --> 06:21.710
And then on the player itself over here we're going to pass knockback direction.

06:23.300 --> 06:23.720
Oh, sorry.

06:23.720 --> 06:24.890
It should be float.

06:27.500 --> 06:28.100
Load.

06:28.100 --> 06:28.910
Okay.

06:29.120 --> 06:30.800
Let's double check it.

06:31.790 --> 06:33.500
Yes, we're giving it knockback direction.

06:33.500 --> 06:34.640
So it's okay.

06:34.730 --> 06:35.750
Going to save it.

06:35.750 --> 06:36.890
Going to go back.

06:40.050 --> 06:41.490
Let's go to play mode.

06:45.440 --> 06:47.570
And boom.

06:49.240 --> 06:51.940
We have a knockback that goes to different directions.

06:51.940 --> 06:52.360
All right.

06:52.360 --> 06:53.440
I don't like the rumble.

06:53.440 --> 06:56.320
I'm going to use bump with a point two.

06:57.730 --> 06:58.210
Yeah.

06:58.210 --> 06:59.200
This is better.

07:01.030 --> 07:05.800
Also, it feels a bit better when you have zoom on the character, so let me just try that.

07:06.760 --> 07:07.990
I'm going to do six.

07:09.670 --> 07:10.870
It feels a bit better.

07:15.290 --> 07:17.420
Anyway, I'm going to keep it like that for now.

07:18.590 --> 07:20.150
And we're good to move on.

07:20.180 --> 07:22.550
Let's do bump point two.

07:22.550 --> 07:24.890
And this will be changed over here.

07:24.890 --> 07:27.710
So we can close this component like that.

07:27.710 --> 07:29.480
And we can go to the next video.
