Let's make our camera shake.
So we're going to move over to hierarchy.
Let's go to Camera Parent.
And we have the main camera as you can see.
So we created a parent game object first.
And then we just made our main camera as a child of that camera parent because we're going to create
animation in this main camera.
So that's why we just create a created an empty parent game object first.
And then we just made that a main camera child of that game object, as you can see.
So you can do that.
Uh, so if you just little bit or worry it, then you can just, uh, check the first and the second
lecture, basically where I explained it about this camera parent and made that follow script, uh,
so you can go and check that.
So now what we're going to do, we're going to make the animation.
So let's select the main camera in our hierarchy underneath our camera parent game object.
Let's go to animation tab.
And let's click on this create button in order to create our animation.
So before we create let me explain.
We're going to have to animation of this main camera.
First we're going to have the ideal one or basically this camera just gonna not gonna shake anything
like that.
It's not gonna do that.
And the second animation clip just gonna be the shake one.
So we're gonna have two animation.
One will be the normal one and another will be the camera shake one.
So let's create that.
So we're going to select our main camera.
And let's click on this create button in animation tab.
And let's go to assets and then animation folder.
And let's move over to this stop animation sub folder.
And we're going to create another sub folder for our main camera animation.
So let's right click the new folder.
And I'm gonna name this folder to something like camera underscore animation.
So we're going to place all of the camera animation into this slot into this folder into this sub folder.
So that's why.
So let's open that up by double clicking on it.
And we have to name the animation what we want to name it.
So I'm going to call this one camera underscore shake animation because this is this cannot be shake
one.
So let's call it camera underscore shake.
And after that let's click on the save button.
And we need to make our animation.
So let's move over to animation tab and make sure you select the main camera in the hierarchy.
And then click on this red button in this animation tab.
So what we're going to do now we're going to move our main camera to the right and to the up a little
bit.
And then we're going to move over to one frame.
And we're going to set back the position to normal.
So let's select our main camera and make sure you just click on this red button in animation tab in
order to capture the animation.
So we're going to select our main camera.
Let's go to Inspector Transform.
And in the X I'm going to move something like 0.10.1.
And in the Y I'm going to put something like -0.1.
And then I'm going to move over to one frame, and I'm going to set back this x position to zero as
well as the y to zero.
So if I just click on this play button we can see now the sake.
And then I'm going to move over to one frame.
Then I will set this x to something like -0.1.
Basically I just want to flip the value.
And in the y I'm going to choose, uh I'm gonna put 0.1.
And after that we're going to move one more frame and then we're going to set back.
So just basically drag this uh line in animation tab, you're going to see and we're going to set back
to zero zero once again.
And now if I just click on this play button we can see the animation by now.
And if you just want to be more intense than, uh, you can just put bigger number in this slot to the
X position, something like 0.2 and the Y you can simply put -0.2.
It's totally up to you.
But I'm gonna go with this point one and after, uh, basically, uh, making the animation, make sure
you just hit that red button in order to capture the animation.
Or you can just leave it like that.
It's automatically gonna capture the animation, and we're gonna create one more animation of this main
camera, which are not gonna be sick at all.
Basically, that will be the normal one.
So normal one.
So we're going to select our main camera one more time and let's go to animation tab.
And then click over here.
And we're going to click on this Create New clip.
And this animation will be the normal one.
So we're going to call it something like camera underscore idle idle.
So we're going to call it idle.
And let's click on that save button.
And we're going to click on this red button.
And we don't want to capture at all anything like that.
So after clicking the red button we're going to click on that to capture.
And we're not doing at all anything as you can see.
So if I moved over to project tab and then animation folder in assets then stop animation and then camera
animation subfolder, we can see we have both the animation, we have the camera set as well as we have
the camera idle.
And I don't want this animation clip to be looped.
So that's why I'm gonna select both of them by holding down shift.
And let's go over to Inspector and I'm going to uncheck this loop time.
So animation just not gonna be loop at all.
So if I just click on this play button in the top you will see the shake animation will be played right
after the game start.
Why?
Because that animation clip is the default one.
So let's have a look before we set.
So as you can see, camera is shaking as soon as the game started.
And if we move over to animator and then select this main camera in the hierarchy, we can see we have
the camera shake as well as the camera idle animation clip.
So we need to make transition between this animation clip.
But before we do, we want this camera idle animation clip to be the default one whenever the game starts.
And once we take damage or our player game object gets destroyed, and then we're gonna play the, uh,
you can simply say the camera shake animation clip.
So let's get out of play mode, and let's select the main camera in the hierarchy and go over to animator
tab.
So we're going to set this camera idle to be the default one.
So we're going to right click on it.
And let's click on this set as layer Default start.
And if we just click on this play button in the top you will see the camera idle animation clip will
be played right after the game start and the camera will not shake anymore.
So as you can see, as soon as the game started, the idle animation is now playing of this main camera.
So let's get out of play mode.
So we also need to make transition from this camera idle to camera shake.
So let's right click on this camera idle and make transition to camera shake.
And we're going to select this transition.
Go over to Inspector.
And we're going to untick this as exit time as well as we're going to set the transition duration to
zero.
Because as soon as we're going to take damage we're going to play this camera shake animation clip right
away.
We don't want any delay.
So that's why we just untick has exit time as well as we set the transition duration to zero.
So we need to choose a condition in which condition we want to play this camera shake animation clip.
So condition slot we can see list is empty.
So let's choose a condition in order to play this camera shake animation clip.
So if we move over to animator in the left side we can see layers, and in the right side we can see
parameters.
So let's click on this plus icon.
And we're going to choose this trigger in the bottom.
And we're going to call this trigger to something like say uh sick.
And now what we're going to do we're going to choose this condition.
So let's go to Inspector and let's click on this plus icon in condition.
And then we're going to choose this shake.
So if I just click on this play button and try to trigger this check parameter manually in animator
tab you will see the camera shake animation will be played.
Why?
Because we have chosen that condition.
As you can see in Inspector, if we just check our trigger parameter.
Basically if we check, uh, if we trigger this check parameter, this animation will be played right
away.
So if I just trigger, as you can see, as soon as we trigger the sick animation just split right away.
And the problem is that we can see in animator tab, we are stuck in this camera shake animation clip
forever.
So we also need to play the idle animation clip after playing this camera shake animation clip 100%.
So let's get out of play mode and let's right click on this camera shake and let's right click on it
and make transition back to our idle.
And now we're gonna choose the transition.
Let's go to Inspector.
And we're going to leave the has exit time and exit time.
We're going to choose point.
Sorry one one basically means we're gonna play the 100% animation clip of this shake.
And then it will just gonna move over to this camera idle animation clip.
And we're going to set the transition duration to zero.
And if we scroll down we're not gonna choose any condition like that.
So after playing the shake animation clip 100%, it's gonna play the camera idle animation clip right
away.
So if I just click on this play button, you will see.
So if we just try to trigger this check parameter manually, you will see the camera check animation
just going to play.
And after playing this camera check animation clip, it's going to automatically play this camera idle
animation clip.
So if I just trigger this check parameter, as you can see, as soon as we trigger the check animation
is playing and after playing 100% of animation, we can see the idle animation is now playing right
away.
So basically what we have to do, we need a.
Basically if we select our main camera then go over to Inspector, we can see an animator component
added to this main camera.
Once we created this animation clip, basically this idle and the check one.
So what we we basically need we need a reference of this animator component of this main camera.
And then we can just trigger this check parameter through our code when we need.
So I'm going to get out of play mode.
I hope you get the idea that how you can do and if we select our camera pattern, we need to go to overrides.
And then we're going to click on this apply all.
Why?
Because if we select our main camera in the hierarchy, we can see an animator component just added.
Once we created this idle animation clip and the plus icon just becomes over here.
Once this animator component added.
So to get rid of that, basically to remove this plus icon, we need to move over to parent game object
and then go over to overrides and then click on Apply All.
As soon as we click now the plus icon is gone by now.
Basically the changes we made in this camera parent game object in the hierarchy it just saved into
this camera parent prefab game object as well.
So basically that is the thing.
So now we need to control this animator.
Uh basically we need to set this shake parameter or we need to trigger this shake parameter.
Once we take damage or once our player game object shoot on this enemy game object.
So I'm going to press down Ctrl S to save my project.