Alright, so we have our third person camera in here.
If I just press play and I can walk around, I can move, but I want to be able to press
the right mouse button to aim down here.
I want to be able to go to a kind of like a rear follow shape camera when I hold the
shift button and I'm running and when I die, I'm going to press K and I'm going to go
to a death state.
So what type of camera system do we want to use?
Well since we're using characters and we're using animation states, the state driven camera
is probably the best camera we can use at this point.
So what we want to do is we want to have a state driven camera in here.
It currently has its own cameras.
I'm going to go ahead and take the player follow camera and I'll just move this up a
little higher.
I'm going to actually stick this inside the state driven camera so you could see these
two are in here.
I'm also going to go to this Cinemachine camera.
I'm going to remove this and now I'm going to go ahead and add my own Cinemachine virtual
cameras to this so that I have the correct cameras for each particular state.
So I'm going to go to Cinemachine.
I'm going to create a new virtual camera and this is going to be called my player run
camera.
I'm going to go ahead and stick this into the state driven camera system.
In here I know that this is going to be a third person follow camera and I need to make
sure of course I'm following my player and I'm going to solo this so I could see what
I am looking at.
I'm going to set my rig offset to zero and I actually want to go right behind the player.
I want to get up close and personal to him as I'm running.
I also want to add some noise to this particular camera.
So whenever we go to this it's all shaky.
So I'm going to do a parallel noise and in here I'm going to choose let's say a four
channel shake and let's go ahead and make sure that it's pretty frequent.
Let's see if there's an amplitude gain or something like that.
Nice little jumpy shake right there.
Once that's created I also want to go here to my Cinemachine extensions and I want to
add a recomposer and I think what I want to do is I want to do a follow scale and it
looks like solo went off.
I want to do like a follow zoom so I get this crazy like fish eye type of lens look going
on here with a real wide focal length which would be kind of cool.
Just show some additional things that we can do with a Cinemachine going crazy with this.
Now I got the run camera in.
That's exactly what I want.
Now I want to create my aim camera.
So I'm going to go to Cinemachine virtual camera and this is going to be my player aim
camera.
I'm just going to go ahead and solo this.
I want to set this as a third person as well.
This is going to be over the shoulder and I'm going to set this higher though.
I'm going to zoom on in so whenever my player pulls out his gun I'm going to look right
over his shoulder and down the barrel.
This is a perfect camera.
I don't need any noise or any other extensions to this so this should be good.
The last camera I want to create is a death camera and I want it to pan automatically.
So the easiest way to do this is to create a blend list camera.
Now I'm going to go ahead and take this blend list camera and drop this into here and this
is going to be my player death camera.
And in here I'm going to have two Cinemachine cameras already in here.
So what I'm going to do is I'm going to start at like let's say this top angle right here
and I'm going to move my camera to this position and then I'm going to go to my next camera
which it's tighter because it has a 40 field of view.
I'm going to go to this position and then I'm going to kind of zoom out.
I'm going to press F and so if I swap between the two you can see this one's the closer
camera and this is the further camera.
Then I'm going to turn off the hold and I'm going to set the ease to like let's say four.
And now if I play the solo camera you'll see that I basically start animating from one
camera to the other.
Very neat easy way to create an animation without actually having to do keyframes and
you can do this for a lot of different cameras and create nice little motion driven scenarios.
Okay, but that's good.
Alright so now we have this state driven camera.
Now we need to tell our animation what is going to be driving it.
So first this thing says we need an animated target.
So I'm going to drop my player armature into the animated target.
This is going to create my states.
So if I click the plus button here I'm going to create a new state and in here I have let's
say all these different states that are currently in this character.
So the first state I actually want to use is the default state.
That way whenever I'm in the default I'm always using the player follow camera.
So basically nothing has changed so far.
Now let's create a new state and I want this state to be running.
Now we see this idle run, walk, blend, neutral run, etc.
What this is is if you look at this idle blend this is actually something called a blend
tree and if you double click inside of it you can see that there's an idle, there's
a walk and then there's a run and depending on your speed it adjusts to the different
values.
Blend trees are commonly used for characters moving left, right, adjusting instead of just
going to one animation or another.
It's a pretty awesome system and we'll get into that in our character course.
What I want to do is I want to basically say in my state machine I want to in my blend
when I do my run I want to do my run camera.
If I just do the idle, walk, run, blend that's just on this animation state.
These are like the subs of the blend tree that I can go to as a state.
So I'm going to set this as the run camera.
This should be a really quick test to see if this works.
So I'm going to go ahead and press play.
I'm going to move around, walk around my scene.
As soon as I hold shift and I start running you'll see that my camera changes and now
I lock into the center.
As soon as I let go I am back to normal.
So we know this blend camera tree is going to work.
So the next thing we want to do is we need to create a death state.
The death state when we look at the character animation needs to occur at any state.
You could die when you're jumping.
You can die in the air.
You can die at jump start.
You could die when you're running, walking, idling, whatever you want to do.
So it's in any state situation.
So in here I'm going to right click.
I'm going to create an empty state and I'm going to call this death.
And in here I'm going to go ahead and grab my animation which is death.
In here I created the animation which is this standing react death backwards one.
Remember I set it to humanoid.
And then in the mixamo I duplicated it and then this created this death animation right
here and I'm literally just going to go ahead and take this death animation and drop it
into my animation.
And then I'm going to go right click make transition and I'm going to click into death.
Cool.
So when does this death state happen?
We need to give it a condition otherwise in any state he's going to die.
So we want to create a condition in our parameters area.
Again, covered a lot in character course.
So but to show you is death one of these different values?
Is it a float?
No.
Is it an int?
1, 0, 2, 3, no.
Is it a bull?
Are you dead?
Is true?
That could happen.
But the easiest way is a trigger.
Death happens once.
It's like a raycast shooting a button.
I'm going to create a trigger and I'm going to call this death.
And so whenever death occurs, I'm going to play death animation.
And when I click on the any state tree, there's a condition down here and I can click on the
condition and it opens up this kind of drop down inside of here.
I can see any condition since it is a death condition.
There's no like anything else is just the trigger.
I'm going to set that to death and then this should work.
So if I go ahead and press play, you're going to see that my animations are going to remain
the same.
But if I were to click on this death button, I should die.
All right, cool.
So that totally worked.
All right.
So once that's done, I want to also create an aim state.
And the aim is not going to occur when I'm jumping.
It's not going to occur when I'm landing and it's not going to occur when I'm in air.
I only want to do it when it's on this state.
So I'm going to create an empty state.
I'm going to call this aim.
And in here, I am going to right click over to aim and I'm going to make a transition
of course back.
And in this aim, I'm going to go ahead and drop this aim animation, which I got from
the pistol idle.
And then in here as well, I want to create a check to see should we be aiming.
So what I'm going to say is that if I hold my mouse button down, I'm aiming.
If I'm not, I am no longer aiming.
I'm back to idle.
Down is true.
Up is false.
This is a bull.
So I'm going to say aim.
And I'm going to click on my idle run.
And you'll notice that I have the aim option in here.
It needs a condition.
I'm going to give it the condition of aim.
If it's true, I'm going to shoot.
And then when I click over here on this condition of aim, when I lift up, as soon as it's false,
I'm going to go back to the blend run.
Okay, cool.
So I got my states in here.
I should be able to test out the aim.
So if I press the button right here.
You'll notice that it takes a while for the aim to occur.
But the aim does occur.
One of the reasons why it does that is inside aim, there's this thing called exit time.
What it is is basically it's not going to initiate until the entire loop has a chance
to play.
So go ahead and turn off exit time for both aim conditions over here.
So you got to make sure you click on the aim and you'll find the exit time.
So basically once I hit play, now if I press this as true, go to automatically aim and
then false, true, false, true, false.
All right, so I got my animation triggers set up.
They're ready to go.
Now I need to be able to tell my state driven camera when to use those states.
So I'm going to go ahead and create a new state.
Now I'm going to say when I hit the death, I'm going to do my death camera.
And then when I do my aim, I'm going to do my aim camera.
So if I go ahead and press play, I should be able to press the aim button and I'll look
right down.
And then if I click back, I'm back to my normal camera.
Look down, back to my normal.
And then if I hit the death, there's my death camera right there.
Boom.
Perfect.
Awesome work right there.
Now, if you wanted to go further and say, I want this to be scriptable, I want to be
able to make this work on my character.
How do I do this out?
Real easy.
All right, so we're going to create a new script.
We're going to call this character state animations.
And then I'm going to go ahead and drop this onto my player armature.
Do, do, do, do, do.
There we go.
And I'm going to go ahead and edit this script.
And really, all I need to do for this to work is I need to access the animator.
I don't need to access Cinemachine or anything else like this.
I just need to access the animator to turn on and off these death states.
So the first thing I'm going to do is I'm going to say private animator.
Anim, and I'm going to get the component, which is the animator.
The animator currently sits right here on the same character.
So anim equals get component animator.
All right, anim is set, declared, and ready to go.
So now I just need to do some button checks.
If I am dead, so I'm going to press K button, then I'm going to play my death animation.
So in this, I'm going to say if input dot get key down, then key code dot K.
Because, you know, usually what you'll want to do is you want to create an entire system
that when, you know, your health goes down to a certain point, you play like your death
function.
But in our instance, we're not going to do that.
We're just going to press the K button and we're going to die.
So I'm going to go ahead and access my anim.
And then I'm going to go ahead and click the space, the period, and it should be able to
pull up our sets and whatever it is, set bulls, set ik, set everything.
So the death was a trigger.
So I'm going to say set trigger, and I need name, the string name of it.
So death.
So if I press K, it's going to hit the set trigger and it's going to create the death.
Now I'm going to do the input as far as the right mouse button goes down.
So if I press the right mouse button down, I want to access the bull, which is aim and
set it to true.
And when I mouse, right mouse button goes up, I'm going to access the bull, set it to
false.
So let's type that out real quick.
Death input dot get key down, key code dot mouse one, which is our right mouse.
If this, if I press this, anim dot set bull, because this is a bull, not a trigger, I want
to go and set my aim.
And if I hit right here, you see how it has your ID and then your value.
My value will be true because I will be aiming.
And if I then do my get key down mouse, I'm sorry mouse key up.
If I do, I get key up mouse one, then I need to set my anim dot set bull aim to false.
Perfect.
So that's the entire script right there.
So if I go back over here and I press play, of course, we know that my run works.
If I right click, now I'm aiming down.
But if I press the K button, boom, I'm dead.
And the only issue that we had with that last one is we never set our target.
So we should probably set our follow to this and our target to this and our V cam number
two, this and this.
And if I solo that, where are we?
Oh, I'm sorry.
I set that to V cam.
What am I doing?
Player armature there and there.
All right.
So let's go ahead into this solo it.
I'm going to move up.
And then I'm also going to adjust where I aim to a higher level.
Let's say right here.
And then with the V cam to let's go ahead and solo that.
Let's see.
We want to reduce this.
Let's go higher.
Let's offset here and let's adjust the aim right there.
So if I go from one camera to the other, perfect.
So if I press K, boom, dead.
Good.
Great work guys.
See you in the next one.