1
00:00:03,200 --> 00:00:07,850
In this lecture, I was setting up a state driven camera so we can have different cameras that zooming

2
00:00:07,850 --> 00:00:11,560
in and out, depending upon whether we're idling or running or climbing our leader.

3
00:00:11,570 --> 00:00:15,380
I'm going to put my tail pellet out of the way because I'm not using it as much as our other things.

4
00:00:15,380 --> 00:00:19,070
I'll put it down here next to the animation, so if I need to get it, I can come in here and click

5
00:00:19,070 --> 00:00:20,390
on my tile pellet.

6
00:00:20,390 --> 00:00:21,230
That's not a problem.

7
00:00:21,230 --> 00:00:24,740
And just a reminder in the animator, when I'm talking about states in this lecture, I'm talking about

8
00:00:24,740 --> 00:00:27,890
these things climbing as a state, running as a state, idling is a state.

9
00:00:27,890 --> 00:00:33,170
That's what I mean by states in the animator, which is the place that manages all of our states and

10
00:00:33,170 --> 00:00:34,190
transitions.

11
00:00:34,190 --> 00:00:40,100
Speaking of states, I'm going to right click in the hierarchy and set a machine and then find the state

12
00:00:40,100 --> 00:00:41,120
driven camera.

13
00:00:41,150 --> 00:00:42,830
Click on that to add that into the scene.

14
00:00:42,830 --> 00:00:45,050
We'll just leave it as I'll just tied it up here a little bit.

15
00:00:45,050 --> 00:00:46,160
State driven camera.

16
00:00:46,160 --> 00:00:49,010
I like to have spaces in here and to organize my cameras.

17
00:00:49,010 --> 00:00:51,020
I'm going to create a new empty game object.

18
00:00:51,020 --> 00:00:52,280
So create empty.

19
00:00:52,310 --> 00:00:55,880
We'll call this cameras just so everything's in the one spot, we can roll it up.

20
00:00:55,880 --> 00:00:58,070
If we don't want to look at it, make sure this is zero.

21
00:00:58,070 --> 00:01:01,160
So right click on Transform Reset that starts back at the zero.

22
00:01:01,160 --> 00:01:03,830
No weirdness will be going on with our Z position.

23
00:01:03,830 --> 00:01:04,550
For example.

24
00:01:04,550 --> 00:01:07,700
Now we'll grab our state driven camera, plop that underneath.

25
00:01:07,700 --> 00:01:11,000
Camera's state driven camera's already got a VM cam one.

26
00:01:11,000 --> 00:01:15,200
It's going to delete that because we have already got ourselves at VM cam, which is the follow cam,

27
00:01:15,200 --> 00:01:19,220
grab the follow cam and put that underneath the state driven camera.

28
00:01:19,220 --> 00:01:19,940
That's really important.

29
00:01:19,940 --> 00:01:24,890
The state driven camera will manage all of the children that it has underneath.

30
00:01:24,890 --> 00:01:27,650
It will say, Do this now, do that now, do that other thing now.

31
00:01:27,650 --> 00:01:29,930
That's what our state driven camera is going to allow us to do.

32
00:01:29,930 --> 00:01:34,160
And also our main camera will pop that underneath the camera's game object.

33
00:01:34,160 --> 00:01:36,920
And once again, I'll just plop this all the way up at the very top.

34
00:01:36,920 --> 00:01:39,350
That's where I like to have my camera's hanging out.

35
00:01:39,350 --> 00:01:43,790
I'm going to rename my fellow camera to be run camera because that's what it's going to be doing.

36
00:01:43,800 --> 00:01:45,740
It'll be the one related to run.

37
00:01:45,740 --> 00:01:52,190
I'm going to click on that and duplicate that and call this one idle camera because it will be hanging

38
00:01:52,190 --> 00:01:57,710
out when we are idling and we'll be using our state driven logic to say which camera will be looking

39
00:01:57,710 --> 00:01:58,040
at.

40
00:01:58,040 --> 00:02:03,590
If we click on state driven camera, you can see that we've got animated target that needs an animator.

41
00:02:03,590 --> 00:02:04,610
So let's click on that.

42
00:02:04,610 --> 00:02:06,140
We've probably only got one animator we do.

43
00:02:06,140 --> 00:02:08,090
It's Ginger the player, double click.

44
00:02:08,090 --> 00:02:12,800
Now our staging camera knows we're using this animator to drive some logic.

45
00:02:12,800 --> 00:02:15,260
Currently we have no state, so let's create a couple of states.

46
00:02:15,260 --> 00:02:20,720
I'll click a plus new state and it allows us to select from the states that we've got in our animator.

47
00:02:20,720 --> 00:02:27,680
So within here I will say that idling the camera we're using is the idle camera that we set up here.

48
00:02:27,680 --> 00:02:28,550
The idle camera.

49
00:02:28,550 --> 00:02:31,700
Now we've hooked a state up to the particular camera.

50
00:02:31,700 --> 00:02:37,220
Click plus again, new state, we will say that the running camera is linked to the running state or

51
00:02:37,220 --> 00:02:40,340
running is linked to run camera idling is linked to idle camera.

52
00:02:40,340 --> 00:02:44,180
Now we need to make these two different because I just duplicated one to make the other.

53
00:02:44,180 --> 00:02:45,440
Let's click on Idle.

54
00:02:45,440 --> 00:02:46,280
What do we want to do in here?

55
00:02:46,280 --> 00:02:50,030
Well, I think when we're idling, let me just click on my scene view again while idling.

56
00:02:50,030 --> 00:02:53,990
What does bring the camera in a little bit to give a little bit of personality of the player?

57
00:02:53,990 --> 00:02:58,940
And now when I click on run camera, you can see that all the framing is in there and if I mess around

58
00:02:58,940 --> 00:03:01,550
with the auto size, it'll show me how that looks.

59
00:03:01,550 --> 00:03:05,210
But if I click on my idle camera and mess around with it, it's not showing it to me.

60
00:03:05,210 --> 00:03:06,320
That's not so helpful.

61
00:03:06,320 --> 00:03:08,750
There's a button up here that says Solo.

62
00:03:08,750 --> 00:03:12,620
If we click on that that basically says, Make this the camera, make it the boss.

63
00:03:12,620 --> 00:03:13,550
So go to that.

64
00:03:13,550 --> 00:03:17,060
When I do that, I can now play around with our auto size and say, You know what?

65
00:03:17,060 --> 00:03:22,400
I'll do this pretty extreme for this lecture process so you can see exactly what's going on.

66
00:03:22,400 --> 00:03:24,980
We'll bring this all the way into, say, four.

67
00:03:24,980 --> 00:03:28,430
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

68
00:03:28,430 --> 00:03:28,760
on.

69
00:03:28,760 --> 00:03:31,700
Click off the solo button to take it back to the logic.

70
00:03:31,700 --> 00:03:37,730
Then I think if we click on play, if we're idling, the camera should zoom into where we are and when

71
00:03:37,730 --> 00:03:43,160
we run, the camera pops back out again, see how the camera's closing and going away, closing, going

72
00:03:43,160 --> 00:03:45,260
away based upon whether we're running or idling.

73
00:03:45,260 --> 00:03:47,300
And so that's all snapping a bit too quickly.

74
00:03:47,300 --> 00:03:49,820
What we can do is look at the default blend.

75
00:03:49,820 --> 00:03:51,920
At the moment, it's happening over 0.5 seconds.

76
00:03:51,920 --> 00:03:57,770
If I want to change this to say 5 seconds, then that means that all camera's the default easing or

77
00:03:57,770 --> 00:03:59,330
blending is at the moment.

78
00:03:59,330 --> 00:04:00,710
It's easy and and ease out.

79
00:04:00,740 --> 00:04:02,270
It's going to be over the course of 5 seconds.

80
00:04:02,270 --> 00:04:04,520
So if I run, it's going to take time.

81
00:04:04,520 --> 00:04:04,680
Run.

82
00:04:04,790 --> 00:04:05,480
I'll hold down here.

83
00:04:05,480 --> 00:04:06,410
Run, run, run, run, run, run.

84
00:04:06,410 --> 00:04:09,230
It's taking 5 seconds to get out to that full camera amount.

85
00:04:09,230 --> 00:04:13,460
When I stop running, it's going to take 5 seconds to zoom in slowly.

86
00:04:13,460 --> 00:04:16,220
So I kind of liked that speed for the zoom in.

87
00:04:16,220 --> 00:04:22,070
If you're just idling and hanging out, I think it's a little bit slow for transitioning into the run,

88
00:04:22,070 --> 00:04:28,340
so I'm going to go and set up some custom blends, create an asset, so click the create asset button.

89
00:04:28,490 --> 00:04:30,020
We'll put this in animations.

90
00:04:30,020 --> 00:04:31,730
This will be state driven camera blends.

91
00:04:31,730 --> 00:04:32,960
That seems pretty good.

92
00:04:32,960 --> 00:04:35,210
Now expand the custom blends rollout.

93
00:04:35,210 --> 00:04:36,770
Click on the plus button here.

94
00:04:36,770 --> 00:04:40,310
And you can see from and to from which state to which state.

95
00:04:40,310 --> 00:04:46,310
Well, specifically, when we go from running to idling, we want that to go slow.

96
00:04:46,310 --> 00:04:49,310
So from run to idle.

97
00:04:49,310 --> 00:04:53,240
So I'm clicking the little selector and then finding the camera I'm interested in.

98
00:04:53,240 --> 00:04:56,180
And how long from when we run to when we idle.

99
00:04:56,180 --> 00:05:01,280
This is the one that I want to have at 5 seconds and then I'll add another state and this is where we

100
00:05:01,280 --> 00:05:02,630
are going from idle.

101
00:05:02,960 --> 00:05:04,290
To run.

102
00:05:04,290 --> 00:05:05,810
Not another state, but another blend.

103
00:05:05,870 --> 00:05:06,350
Sorry.

104
00:05:06,350 --> 00:05:07,790
And this time we'll make it much quicker.

105
00:05:07,790 --> 00:05:09,290
So I'll make it 1/2.

106
00:05:09,290 --> 00:05:10,190
Let's see how that looks.

107
00:05:10,190 --> 00:05:14,750
That means that we've got a longer transition from run to idle.

108
00:05:14,900 --> 00:05:16,640
So that was running to idle.

109
00:05:16,640 --> 00:05:21,170
When I run, it goes out pretty quick and then when I'm standing around, it eases its way back in slowly.

110
00:05:21,170 --> 00:05:21,920
Run, run, run.

111
00:05:21,920 --> 00:05:25,670
Easing its way back in and the state where we've got idling, I want to wait a little bit.

112
00:05:25,670 --> 00:05:30,140
So when we finish doing whatever else it is that we're doing, just wait a moment, because maybe you're

113
00:05:30,140 --> 00:05:32,450
not actually hanging around, idling, doing nothing.

114
00:05:32,450 --> 00:05:35,180
Maybe it's just that you're getting ready to do a jump.

115
00:05:35,180 --> 00:05:36,650
So we'll wait for a second.

116
00:05:36,650 --> 00:05:41,530
I think so then if I run, run, run, run, run, run, run, run, run.

117
00:05:41,540 --> 00:05:45,890
And then wait 1/2 and now slowly start to transition in.

118
00:05:45,890 --> 00:05:48,470
I think that's a nicer way of doing it.

119
00:05:48,470 --> 00:05:53,450
Now, if you had something else, for example, if you were to fall in the water and you wanted the

120
00:05:53,450 --> 00:05:59,000
player to have a reaction, a camera reaction instantly, then you could add a new state and say from

121
00:05:59,000 --> 00:06:01,160
any camera, it doesn't matter which camera.

122
00:06:01,160 --> 00:06:06,110
When we go into our water camera, we want that to be a certain way.

123
00:06:06,110 --> 00:06:08,030
You don't have to go and hook everything up.

124
00:06:08,030 --> 00:06:10,040
So this was any camera into water camera.

125
00:06:10,040 --> 00:06:11,150
We don't have a water camera yet.

126
00:06:11,150 --> 00:06:14,960
Obviously, you can have it happen from any camera going into that particular camera.

127
00:06:14,960 --> 00:06:15,770
So that's a good thing.

128
00:06:15,770 --> 00:06:19,550
So if you end up with ten cameras in your game, you don't have to go through that full matrix of every

129
00:06:19,550 --> 00:06:21,020
single camera to every other camera.

130
00:06:21,020 --> 00:06:23,000
You can do this, any camera option.

131
00:06:23,000 --> 00:06:26,630
So I'm going to minus that for now to get rid of it and give you a challenge.

132
00:06:26,690 --> 00:06:30,560
The challenge is to add a camera for when you're climbing on your ladder.

133
00:06:30,560 --> 00:06:32,660
That's an additional state you need for the camera.

134
00:06:32,660 --> 00:06:37,190
While we're climbing ladders, make sure that the blending to and from the camera is how you would like

135
00:06:37,190 --> 00:06:39,980
it to be with the right sort of wait time and the right amount of blend.

136
00:06:39,980 --> 00:06:41,150
So there's a challenge.

137
00:06:41,150 --> 00:06:42,770
Take that on C back here when you're done.

138
00:06:46,020 --> 00:06:50,120
Our first step in here is we need to duplicate something or duplicate the idol camera.

139
00:06:50,130 --> 00:06:55,200
Control dx rename this to be the ladder camera.

140
00:06:55,350 --> 00:06:56,240
Excellent.

141
00:06:56,250 --> 00:06:58,250
And I'll change the lens size.

142
00:06:58,260 --> 00:07:01,380
You know, I'll go really extreme on this just so we can see exactly what's happening.

143
00:07:01,380 --> 00:07:03,690
I will have everything zoom out.

144
00:07:03,690 --> 00:07:05,190
I think that's probably a nice way of doing it.

145
00:07:05,190 --> 00:07:07,710
When you're on the ladder, you can view the world and see what's going.

146
00:07:07,710 --> 00:07:09,410
So we'll change this to eight.

147
00:07:09,420 --> 00:07:10,120
I think that should be enough.

148
00:07:10,140 --> 00:07:10,920
What was our run?

149
00:07:10,920 --> 00:07:11,940
Run was five.

150
00:07:11,940 --> 00:07:12,840
Idol was four.

151
00:07:12,870 --> 00:07:13,950
Maybe we'll make this seven.

152
00:07:13,950 --> 00:07:20,460
Not quite as extreme, but still reasonably extreme on our lend lens, although size.

153
00:07:20,460 --> 00:07:25,260
Now we need to find the state driven camera click on plus where we have our state and our camera, not

154
00:07:25,260 --> 00:07:28,350
the blend just yet but click on plus new state.

155
00:07:28,350 --> 00:07:33,150
We'll make this the climbing state and that will be for the latter camera, the wait time.

156
00:07:33,150 --> 00:07:34,890
Do we want to wait when we jump on the ladder?

157
00:07:35,010 --> 00:07:35,520
Yeah, we will.

158
00:07:35,520 --> 00:07:37,170
We'll do the 1/2 wait again.

159
00:07:37,170 --> 00:07:38,850
In terms of the blend, I'll click.

160
00:07:38,850 --> 00:07:40,920
Plus, this will be what I was mentioning before.

161
00:07:40,920 --> 00:07:45,480
I was kind of giving you a hint the any camera when you get yourself onto a ladder, how long do we

162
00:07:45,480 --> 00:07:45,900
want to take?

163
00:07:45,900 --> 00:07:48,090
We'll make this pretty quick just to have a bit of fun here.

164
00:07:48,090 --> 00:07:49,030
We'll make it 0.5.

165
00:07:49,350 --> 00:07:50,910
It's going to zoom out very quickly.

166
00:07:50,910 --> 00:07:55,080
And while we're here, we should also do it the other way around, which is when you leave the ladder

167
00:07:55,080 --> 00:07:58,290
and you go to any other camera, will make this pretty quick as well.

168
00:07:58,290 --> 00:07:59,370
Make it 1/2.

169
00:07:59,370 --> 00:08:01,020
Just guessing on all these things here.

170
00:08:01,050 --> 00:08:02,070
Click on play.

171
00:08:02,070 --> 00:08:03,510
Find myself a ladder.

172
00:08:04,080 --> 00:08:04,770
It's a little bit sad.

173
00:08:04,770 --> 00:08:06,150
We've just got this one little ladder.

174
00:08:06,180 --> 00:08:11,090
Okay, when we run, we zoom out a little bit, jump on the ladder, waiting a moment, and then we're

175
00:08:11,280 --> 00:08:15,540
so we're actually idling when we're just standing around doing nothing, that's fine.

176
00:08:15,540 --> 00:08:18,300
If we're climbing, it looks like we need to snap into that more quickly.

177
00:08:18,300 --> 00:08:19,620
So let's do that.

178
00:08:19,620 --> 00:08:21,120
We'll just make the wait time.

179
00:08:21,120 --> 00:08:26,160
Zero on our climbing the ladder, wait time, climb ladder zero.

180
00:08:26,160 --> 00:08:30,960
And the ease is going to happen pretty quickly as well, just so we can illustrate it.

181
00:08:30,960 --> 00:08:33,270
I mean, you will implement this however you want in your game.

182
00:08:33,270 --> 00:08:34,169
We're just setting it up now.

183
00:08:34,169 --> 00:08:38,880
So we've got some examples of how these things work, climb the ladder, it's zooms out and then as

184
00:08:38,880 --> 00:08:45,600
zooms back in pretty quick, we could have it go a little bit slower from climbing ladder to other states.

185
00:08:45,600 --> 00:08:47,160
That would be the last thing I'd do in here.

186
00:08:47,160 --> 00:08:53,160
So we'll make the ease more like a 3 seconds if we go from the ladder to anything else.

187
00:08:53,160 --> 00:08:54,420
So it's not quite so snappy.

188
00:08:54,420 --> 00:08:54,810
Snappy.

189
00:08:54,810 --> 00:08:58,230
If you stop and you're hanging around, last look here just to make sure it's all doing it.

190
00:08:58,230 --> 00:08:59,700
Okay, we're on the ladder, we're climbing.

191
00:08:59,700 --> 00:09:00,960
It zooms out pretty quick way.

192
00:09:01,060 --> 00:09:02,640
We're in it slowly coming back in.

193
00:09:02,640 --> 00:09:05,340
So if I jump off, it's going back to where it needs to go to.

194
00:09:05,340 --> 00:09:07,920
But if I climb the ladder, it's giving me that nice big view.

195
00:09:07,920 --> 00:09:08,220
Okay.

196
00:09:08,220 --> 00:09:10,860
Yeah, that's feeling a pretty nice, smooth ish.

197
00:09:10,860 --> 00:09:12,990
You don't have to go so extreme with your tuning on this.

198
00:09:12,990 --> 00:09:17,490
This is just so that we can see it and start understanding how all of this logic works and this tool

199
00:09:17,490 --> 00:09:17,700
works.

200
00:09:17,700 --> 00:09:22,710
So it's a really cool addition to our tool chest of things we can do with center machine and in unity.

201
00:09:22,710 --> 00:09:23,460
So great stuff.

202
00:09:23,460 --> 00:09:24,570
I'll see you in the next lecture.

