In this lecture, I was setting up a state driven camera so we can have different cameras that zooming
in and out, depending upon whether we're idling or running or climbing our leader.
I'm going to put my tail pellet out of the way because I'm not using it as much as our other things.
I'll put it down here next to the animation, so if I need to get it, I can come in here and click
on my tile pellet.
That's not a problem.
And just a reminder in the animator, when I'm talking about states in this lecture, I'm talking about
these things climbing as a state, running as a state, idling is a state.
That's what I mean by states in the animator, which is the place that manages all of our states and
transitions.
Speaking of states, I'm going to right click in the hierarchy and set a machine and then find the state
driven camera.
Click on that to add that into the scene.
We'll just leave it as I'll just tied it up here a little bit.
State driven camera.
I like to have spaces in here and to organize my cameras.
I'm going to create a new empty game object.
So create empty.
We'll call this cameras just so everything's in the one spot, we can roll it up.
If we don't want to look at it, make sure this is zero.
So right click on Transform Reset that starts back at the zero.
No weirdness will be going on with our Z position.
For example.
Now we'll grab our state driven camera, plop that underneath.
Camera's state driven camera's already got a VM cam one.
It's going to delete that because we have already got ourselves at VM cam, which is the follow cam,
grab the follow cam and put that underneath the state driven camera.
That's really important.
The state driven camera will manage all of the children that it has underneath.
It will say, Do this now, do that now, do that other thing now.
That's what our state driven camera is going to allow us to do.
And also our main camera will pop that underneath the camera's game object.
And once again, I'll just plop this all the way up at the very top.
That's where I like to have my camera's hanging out.
I'm going to rename my fellow camera to be run camera because that's what it's going to be doing.
It'll be the one related to run.
I'm going to click on that and duplicate that and call this one idle camera because it will be hanging
out when we are idling and we'll be using our state driven logic to say which camera will be looking
at.
If we click on state driven camera, you can see that we've got animated target that needs an animator.
So let's click on that.
We've probably only got one animator we do.
It's Ginger the player, double click.
Now our staging camera knows we're using this animator to drive some logic.
Currently we have no state, so let's create a couple of states.
I'll click a plus new state and it allows us to select from the states that we've got in our animator.
So within here I will say that idling the camera we're using is the idle camera that we set up here.
The idle camera.
Now we've hooked a state up to the particular camera.
Click plus again, new state, we will say that the running camera is linked to the running state or
running is linked to run camera idling is linked to idle camera.
Now we need to make these two different because I just duplicated one to make the other.
Let's click on Idle.
What do we want to do in here?
Well, I think when we're idling, let me just click on my scene view again while idling.
What does bring the camera in a little bit to give a little bit of personality of the player?
And now when I click on run camera, you can see that all the framing is in there and if I mess around
with the auto size, it'll show me how that looks.
But if I click on my idle camera and mess around with it, it's not showing it to me.
That's not so helpful.
There's a button up here that says Solo.
If we click on that that basically says, Make this the camera, make it the boss.
So go to that.
When I do that, I can now play around with our auto size and say, You know what?
I'll do this pretty extreme for this lecture process so you can see exactly what's going on.
We'll bring this all the way into, say, four.
I think that's going to be a little bit yuck, but I'll do it just so we can see exactly what's going
on.
Click off the solo button to take it back to the logic.
Then I think if we click on play, if we're idling, the camera should zoom into where we are and when
we run, the camera pops back out again, see how the camera's closing and going away, closing, going
away based upon whether we're running or idling.
And so that's all snapping a bit too quickly.
What we can do is look at the default blend.
At the moment, it's happening over 0.5 seconds.
If I want to change this to say 5 seconds, then that means that all camera's the default easing or
blending is at the moment.
It's easy and and ease out.
It's going to be over the course of 5 seconds.
So if I run, it's going to take time.
Run.
I'll hold down here.
Run, run, run, run, run, run.
It's taking 5 seconds to get out to that full camera amount.
When I stop running, it's going to take 5 seconds to zoom in slowly.
So I kind of liked that speed for the zoom in.
If you're just idling and hanging out, I think it's a little bit slow for transitioning into the run,
so I'm going to go and set up some custom blends, create an asset, so click the create asset button.
We'll put this in animations.
This will be state driven camera blends.
That seems pretty good.
Now expand the custom blends rollout.
Click on the plus button here.
And you can see from and to from which state to which state.
Well, specifically, when we go from running to idling, we want that to go slow.
So from run to idle.
So I'm clicking the little selector and then finding the camera I'm interested in.
And how long from when we run to when we idle.
This is the one that I want to have at 5 seconds and then I'll add another state and this is where we
are going from idle.
To run.
Not another state, but another blend.
Sorry.
And this time we'll make it much quicker.
So I'll make it 1/2.
Let's see how that looks.
That means that we've got a longer transition from run to idle.
So that was running to idle.
When I run, it goes out pretty quick and then when I'm standing around, it eases its way back in slowly.
Run, run, run.
Easing its way back in and the state where we've got idling, I want to wait a little bit.
So when we finish doing whatever else it is that we're doing, just wait a moment, because maybe you're
not actually hanging around, idling, doing nothing.
Maybe it's just that you're getting ready to do a jump.
So we'll wait for a second.
I think so then if I run, run, run, run, run, run, run, run, run.
And then wait 1/2 and now slowly start to transition in.
I think that's a nicer way of doing it.
Now, if you had something else, for example, if you were to fall in the water and you wanted the
player to have a reaction, a camera reaction instantly, then you could add a new state and say from
any camera, it doesn't matter which camera.
When we go into our water camera, we want that to be a certain way.
You don't have to go and hook everything up.
So this was any camera into water camera.
We don't have a water camera yet.
Obviously, you can have it happen from any camera going into that particular camera.
So that's a good thing.
So if you end up with ten cameras in your game, you don't have to go through that full matrix of every
single camera to every other camera.
You can do this, any camera option.
So I'm going to minus that for now to get rid of it and give you a challenge.
The challenge is to add a camera for when you're climbing on your ladder.
That's an additional state you need for the camera.
While we're climbing ladders, make sure that the blending to and from the camera is how you would like
it to be with the right sort of wait time and the right amount of blend.
So there's a challenge.
Take that on C back here when you're done.
Our first step in here is we need to duplicate something or duplicate the idol camera.
Control dx rename this to be the ladder camera.
Excellent.
And I'll change the lens size.
You know, I'll go really extreme on this just so we can see exactly what's happening.
I will have everything zoom out.
I think that's probably a nice way of doing it.
When you're on the ladder, you can view the world and see what's going.
So we'll change this to eight.
I think that should be enough.
What was our run?
Run was five.
Idol was four.
Maybe we'll make this seven.
Not quite as extreme, but still reasonably extreme on our lend lens, although size.
Now we need to find the state driven camera click on plus where we have our state and our camera, not
the blend just yet but click on plus new state.
We'll make this the climbing state and that will be for the latter camera, the wait time.
Do we want to wait when we jump on the ladder?
Yeah, we will.
We'll do the 1/2 wait again.
In terms of the blend, I'll click.
Plus, this will be what I was mentioning before.
I was kind of giving you a hint the any camera when you get yourself onto a ladder, how long do we
want to take?
We'll make this pretty quick just to have a bit of fun here.
We'll make it 0.5.
It's going to zoom out very quickly.
And while we're here, we should also do it the other way around, which is when you leave the ladder
and you go to any other camera, will make this pretty quick as well.
Make it 1/2.
Just guessing on all these things here.
Click on play.
Find myself a ladder.
It's a little bit sad.
We've just got this one little ladder.
Okay, when we run, we zoom out a little bit, jump on the ladder, waiting a moment, and then we're
so we're actually idling when we're just standing around doing nothing, that's fine.
If we're climbing, it looks like we need to snap into that more quickly.
So let's do that.
We'll just make the wait time.
Zero on our climbing the ladder, wait time, climb ladder zero.
And the ease is going to happen pretty quickly as well, just so we can illustrate it.
I mean, you will implement this however you want in your game.
We're just setting it up now.
So we've got some examples of how these things work, climb the ladder, it's zooms out and then as
zooms back in pretty quick, we could have it go a little bit slower from climbing ladder to other states.
That would be the last thing I'd do in here.
So we'll make the ease more like a 3 seconds if we go from the ladder to anything else.
So it's not quite so snappy.
Snappy.
If you stop and you're hanging around, last look here just to make sure it's all doing it.
Okay, we're on the ladder, we're climbing.
It zooms out pretty quick way.
We're in it slowly coming back in.
So if I jump off, it's going back to where it needs to go to.
But if I climb the ladder, it's giving me that nice big view.
Okay.
Yeah, that's feeling a pretty nice, smooth ish.
You don't have to go so extreme with your tuning on this.
This is just so that we can see it and start understanding how all of this logic works and this tool
works.
So it's a really cool addition to our tool chest of things we can do with center machine and in unity.
So great stuff.
I'll see you in the next lecture.