Welcome back my fellow game developers
to a brand new video.
And in this one, whenever we start shooting,
we no longer have this boring thing that happens.
We actually have shaking.
So when we shoot, there we go.
You can see whenever we should,
we have some kind of shaking,
so it adds a level of intensity.
Obviously, the intensity on the shotgun is just too much,
but as you can see,
each weapon has its own intensity.
So notice the rifle,
notice the gun, and notice the shotgun. There you go.
So you can see we have
different intensities for different weapons.
So let's not waste any more time.
And let's get started.
Oh, okay, So now what we want to do is we
want to add a bit of
intensity to the way we are shooting.
So currently everything is working fine.
We are shooting with our weapons.
We can change them to different weapons.
We can kill enemies.
Everything is good, but there
is still something bothering
me and that is that the shooting isn't that exciting.
So we have the shooting,
we don't actually feel it.
We see it.
It doesn't impact, but we don't feel it inside of us.
So what we're going to do is we're going
to add a bit of shaking to the camera.
And thankfully, it's extremely
easy when it comes to using a sinner machine.
Before having a single machine,
it would take a lot whenever you want to
make the cam shake and it
wouldn't work. It's sometimes did.
So let's not waste any more time.
And let's go ahead into
the virtual camera and add something
called the basic multi-channel Berlin under the noise.
So you want to ask me,
what is the basic multi-channel Berlin?
I have no idea, but I know that it creates noise.
So if you want to delve deeper into that beam,
I guess I would be very happy.
So her that out of the way.
Let's see what happens in here.
We have different types of profiles,
noise, Let's not call it knows anymore.
And we can change this to have various different aspects.
You can go ahead and read about all of these.
I'm really don't know what they actually do.
I'm not that deep into SONA machine,
but what I do know is we can use
60 shake and we have
the amplitude and the frequency gain.
So if I run the game,
you'll notice that we will have shaking right now.
Okay, So there you go.
You can see the little shaking
and you can see the camera how it's shaking.
If I increase the amplitude, there you go,
you can see that as I increase,
we have more and more and more shaking
until we can handle it. No war.
Let's set it to 0 for now,
you can see I can also create an offset.
So if I set it to one and I increase on the y,
I think on the Y there will be more shaking,
but let's keep it at 0.
We can also increase the frequency,
and this will add to the frequency of the shaking.
So let's keep it at one.
Let's set it back to 0.
And let's find a way to control this
shaking whenever we are actually shooting.
So to do that, I'm going to create a new script.
So I'm going to go into the script,
Let's right-click and create a folder for the cameras.
Because later on we might have a camera controller.
And let's go ahead and create a C sharp script and call
it the shake, camp.
Hit Enter, wait for it to compile.
And we're going to add it to
the virtual camera. And there we go.
Now we have a script in here.
I'm going to open it up and we
are going to do a couple of things.
So first thing, first,
we need to be using cin a machine.
This will allow us to access
different things inside the machine,
just like using Unity engine doc UI
to access things in the UI canvas.
The next thing we're going to do is
create a couple of variables.
Now bear with me.
This will be a bit strange,
but you will understand everything.
First, obviously we need
a reference to the virtual camera.
So I'm going to create a private sin a machine.
Actually let's just virtual camera,
center machine virtual camera.
And I'm going to call it
my virtual camera just to keep things very simple.
Next, we're going to create another private variable,
which is going to be the multi channel purlin.
And we're going to call this the noise.
So as we said,
this animation, basic multi-channel Berlin.
This is the last time I'm going to save the song world.
There it is, right here,
and we will need a reference to it and the noise.
So back in here, what else do we need?
Well, I think we will need to
create an instance of this because we don't
want to keep looking for it and we just
needed once. I believe.
So, I'm going to make this a public static.
And we'll make this a type of shaky, shaky cam.
And it's going to be called
instance in stance. And there we go.
And in a way from now on,
whenever we want to instantiate an instance,
it's always and the awake.
So instance equals this.
Great. Next, let's go ahead and set up everything.
And as long as we have the awake now let's set
the virtual camera MD noise in here.
So first thing first,
my virtual camera, what is it equal to?
Well, it's very simple.
We are going to get the component,
get component, and we're going to get
the virtual camera. There we go.
So now we have access to the virtual camera.
Then we'll need to get the noise.
So noise is equal to get out or sorry,
noise is equal to my virtual camera dot get.
And you can see right here that we have
this gets in a machine component.
So what the problem is or not the problem actually,
why do we have gets in a machine component and
why can't we just get a normal component?
Well, because if I go in here and four,
I do that, just let me fill this end.
So this will be the multichannel purlin.
There we go.
So why do we use the get cinema machine component?
12 silane machines are a bit
tricky and that's why I recommend that
you go and look through
the documentations and learn everything about.
You can actually, by the way,
you sell machines to create
trailers and cut-scenes and so on.
So it's a very, very powerful tool.
You will learn what it does.
So you can see right here that these are different,
let's say components inside of the virtual camera.
And what's the problem in here for some reason.
Okay, So it wasn't opening up.
Did we say that we needed the body?
Oh, okay.
So there we go.
For some reason it wasn't opening up
Cinema machine and make this a 60 cam.
Save that.
Okay, let's continue on.
Now that we have access to the noise,
what we're going to do is we're going to first
of all delete or remove the start and update.
And we're going to create
a method to actually start shaking.
So I'm going to create a public void
and we'll call this the shake camera.
And inside of shake camera,
I'm going to take in a float of intensity.
And this intensity will be translated into the noise.
So if we look down here under the noise,
we have the amplitude gain.
Let's access that.
So amplitude gain their ego
and we have the little m behind it.
But this is the name of the variable that we're
accessing and we're going to sell it as the intensity.
And why do we have this intensity parameter while?
Because every time we shoot our weapon,
we want to have a certain intensity.
So for example, the shotgun should add a
bit more shaking the Arno,
the whatever it is,
the rifle will add a bit less
shaking the gun shouldn't shake almost at all.
But for now, let's go ahead and
call this method right here.
And we're going to go ahead and
first of all acts as the shaken,
for instance, shake camera.
And let's just give it for now 55.
So we will create shaking using
five intensity and we'll see how that looks.
So I'm going to wait for this to compile.
I'm going to run the game.
And now we should see that when I shoot.
There you go.
You can see that I have the shaking.
Now, there are two problems in here.
The first one is we have a lot of shaking.
The second one is that if I change into another gun,
the shaking is the same.
If we test it out, it will be the same. Trust me.
That doesn't seem like that,
but let's say I tried to use the gun.
So you can see now when I shoot,
the intensity is the same and we don't want that.
So I'm going to issue you a small challenge.
You are going to make the camera shake.
So create two variables for each weapon.
14, the intensity of the shake,
and one for the time we keep shaking,
we don't want to keep shaking forever.
Second, you'll need to add a parameter
to the shape method that takes in the time.
Also, you'll need to stop the
shaking using a co-routine and
you need to call the method
shake camp every time we should become,
I think the last point we've already did.
So pause the video right now and go do the shallow lunge.
Okay, welcome back.
So how did you get all of that?
So first thing I'm going to do is in here I'm
going to create a serialized field of type float.
And it's going to be a weapons shake intensity.
And the weapons.
What?
Weapon? Shake time.
And let's remove the weapons and make it happen.
So now we have the intensity and the shake time.
Next thing we're going to do,
what should we do?
Let's see the challenge or even forgot as a parameter.
Okay, so we go back in here and we add
a float time or shaking time.
Shaking time, then we'll
need to stop the shaking using a co-routine.
So in here I'm going to create
an enumerator and it's
going to be called the stop shaking.
So stop shaking and it's going to take in
a variable in here which is no time to wait.
And as always, we are going to yield, return.
New, wait, four seconds, time, wait.
And in here after we finish,
we are going to get the noise again, dot amplitude.
And we're going to set it back to 0.
Save that.
And we are going to start the court in up here.
So start coroutine.
Stop shaking, Please.
And we're going to shake time.
Shaking time. Say that finally,
there is something in here.
So there we go. So weapon
shake intensity and weapon shake time.
Save that.
I believe this is everything that we need to do.
So we call, we get the instance of the shakeup,
we access the method,
give it the intensity of the weapon,
we give it the time it needs to keep shaking.
And then we call this method right here,
which takes in the intensity shaking time,
gives us the intensity to the noise.
It starts shaken and then starts a cold thing
that will stop the shaking after a bit of time.
So with that done,
we save all of that.
We go back in here,
we have the Why does the noise keep closing?
Did you notice that every
single time for some reason there is
some kind something not completely right with this.
I hope it works.
So I'm going to set it to 0.
Save that, run the game.
Oh, and I forgot to add to each some shaking.
So shotgun,
what's the intensity of the shake on a shotgun?
Let's make it six.
And the time is maybe two seconds. I don't know.
I didn't test this.
The intensity on a rifle will be
four with a shaking time of one.
And on the pistol is going to be a
three for the shaking time of 0.5.
Save that, run the game.
And let's test our weapons out for the shaking.
So I'm going to maximize on
play to make it look much nicer.
I believe this will work.
I don't think we have an error.
So now when I shoot with a rifle, go and i,
if i computing we have shaking all the time,
then when I choose the pistol,
it's a bit less,
so 0.5 seconds and the shaking is a bit smaller.
And then we have the shotgun,
which should take lot and for MLA.
So boom, there we go.
We are dropping some kind of nuclear bomb.
But obviously these all need a bit of tweaking.
I will do a bit of tweaking here.
We don't want to have that much shaking.
We will have a little bit less,
but it always comes back to you.
What do you want your shaking to feel like?
Does it have to be intense?
Does it not have to be intense?
We are going to commit all of
our changes and we are going to call
this the as a shaky cam when I shoot.
Comment those. And there you go.
I believe this will be the last video in
this section of the advanced weapons system.
We've added our guns later on we will be picking sum up.
We will see how we are going to
be finding all of our guns.
We learnt how to switch the weapons.
We learned how to add them to the UI.
We added a fire rate,
we created an amazing shooting system
and I hope you're enjoying.
I hope you'll have to review it helped me out a
lot and I'll see you in the next one.