Hello guys.
Welcome to the video.
In this one I want to show you how to make camera shake.
It will improve the feedback of the game very much and I like to use it a lot.
So let's do it.
It's pretty easy to set up and before we do that, let's do a bit of like general cleanup in the hierarchy.
So for the main camera I want to make a parent.
It's going to be camera.
Manager.
And for these two, let's make a parent.
Level camera just like that, and I'm going to place it.
Wait a second.
Going to place it like that.
Okay.
Very nice.
Now let's go to scripts and let's make a script camera manager.
Then we're going to take the camera manager and put the script on.
Camera manager.
Okay.
It is very easy to make a screen shake.
We just need to add component of um.
Impulse source, Cinemachine impulse source like that.
And we need to add Cinemachine impulse listener on the camera.
So here we're going to go to camera.
And we're going to add the extension of Cinemachine impulse listener.
Let's click it.
So now this camera listens to the impulses we have.
And over here we have a source of the impulse.
And we just need to get this component and type dot generate impulse.
Simple as that.
Now let's go to camera manager.
First, I want to make it work as a single tone.
So I'm going to make public static camera manager instance and then awake instance equals to this.
Now let's make a header.
Header camera.
Shake.
And we're going to do centralized field private vector two shake velocity.
And we need component of the source.
And I don't think we need to see it in the inspector.
So I'm going to just do private Cinemachine impulse source.
And let's just call it impulse source.
Nice.
Now we need to get this component.
So I'm going to do input source equals to get component of cinemachine input source.
And then we need a method that will check the camera.
So public void.
Camera shake.
In which we want to update velocity on this component.
So I'm going to do impulse source.
Default velocity equals to new vector.
Two.
Shake.
Velocity.
X.
Shake velocity.
Dot y.
Very nice.
And then we're going to need to do input source dot generate impulse.
Simple as that.
All right, let's save this.
Now.
Let's go to player script.
We need to find this knockback method and if we do not return from a method, means we can do a screen
shake and we're going to do camera manager dot instance.
Camera shake.
I don't like to call it camera shake.
Can I call it screen shake?
Okay.
Screen shake.
All right, this is better.
Let's save this.
Let's go to player.
Yes.
We have this method here.
It's okay.
Now let's go back to unity.
We can define the velocity over here.
And for example, I want to do 0.75 by 0.75.
Let's go to play mode.
And now every time I'm getting knocked back, we can see a screen shake, which is very nice, I like
it.
Now there are different shake modes.
Uh, let me show it to you so you can go over here and change the shape of the impulse to, for example,
recoil.
This is how it's going to feel now.
There is also explosion.
Or there is a rumble.
Also, you can increase the duration of this, let's say one second and it's gonna work differently.
So now it's up to you how you want it to work.
You just need to decide on the final filling you want to have.
And there is a recoil.
You just define the power and the length.
You could also test for subway here with different values.
Right.
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
one.
And let's see.
Yet.
It's not that bad.
I like it, so maybe I'm going to use it all the feels like it's too strong.
Maybe 0.7.
Okay.
I'm going to keep it.
I'm going to see how I feel about it.
Most likely I'm going to get back to bump.
As this one is good with the lower value.
Yeah, but again, you can see it's all up to what you like.
You know, I'm going to keep ramble for now.
Let's see how it feels during the testing.
All right.
So I'm going to, uh, go off the play mode.
Let's change it to ramble.
Let's do 0.5 and we define shake velocity over here.
So 75 by 75 looks good to me.
I only want to apply the knockback direction.
So camera moves into the direction we were knocked.
Uh let's go to camera manager.
And over here we're going to pass it.
Uh, shake direction.
And then on the player.
And then over here we're going to multiply x by the shake direction.
And then on the player itself over here we're going to pass knockback direction.
Oh, sorry.
It should be float.
Load.
Okay.
Let's double check it.
Yes, we're giving it knockback direction.
So it's okay.
Going to save it.
Going to go back.
Let's go to play mode.
And boom.
We have a knockback that goes to different directions.
All right.
I don't like the rumble.
I'm going to use bump with a point two.
Yeah.
This is better.
Also, it feels a bit better when you have zoom on the character, so let me just try that.
I'm going to do six.
It feels a bit better.
Anyway, I'm going to keep it like that for now.
And we're good to move on.
Let's do bump point two.
And this will be changed over here.
So we can close this component like that.
And we can go to the next video.