﻿1
00:00:04,470 --> 00:00:05,310
‫Hello and welcome.

2
00:00:05,310 --> 00:00:11,280
‫This lecture we are going to be filling out our animation state machine so that there are more states

3
00:00:11,280 --> 00:00:16,320
‫here allowing us to have a animation that jumps us into that initial jump state.

4
00:00:16,320 --> 00:00:21,840
‫As you can see, there's a little bit more spring to my jump and we are going to learn about such things

5
00:00:21,840 --> 00:00:26,820
‫as automatic transitions and how to nest one state machine within another, which is what we're going

6
00:00:26,820 --> 00:00:28,830
‫to do for ad death animation.

7
00:00:28,830 --> 00:00:31,980
‫Now let's dive in and see how it works.

8
00:00:32,430 --> 00:00:41,070
‫So as promised in the last lecture, we're going to hook up our is airborne variable to the gameplay.

9
00:00:41,100 --> 00:00:48,570
‫Now the way we're going to do this is to get from the pawn or particularly from our shooter character.

10
00:00:48,810 --> 00:00:54,840
‫We want to find out essentially whether the character is airborne.

11
00:00:55,200 --> 00:01:01,620
‫And I find that the only way you can do this is essentially through the character movement component.

12
00:01:01,620 --> 00:01:02,820
‫So let me show you what I mean.

13
00:01:02,820 --> 00:01:07,800
‫If we go to our cast node that is casting to the shooter character, then we can drag off of this.

14
00:01:07,800 --> 00:01:12,660
‫In fact, what we can do is a more general cast in this particular instance because we don't need the

15
00:01:12,660 --> 00:01:16,080
‫specific information associated with is dead.

16
00:01:16,380 --> 00:01:23,910
‫So what I'm going to do here is we'll take this pin, the pawn owner, and we're going to do a cast

17
00:01:23,910 --> 00:01:30,360
‫to a character in this case, because all we need to know is that this is a character instance.

18
00:01:30,360 --> 00:01:35,880
‫Then we're going to add a new execution pin up at the sequence node, drag that down to our cast to

19
00:01:35,880 --> 00:01:39,690
‫character, and then from the character will drag off of its character pin.

20
00:01:39,690 --> 00:01:46,200
‫And we're going to look for basically something along the line of airborne nothing there maybe jump

21
00:01:46,230 --> 00:01:53,850
‫seems to be more interesting it's saying is jump providing force can jump jump all that sort of stuff.

22
00:01:53,850 --> 00:01:56,400
‫We got something there, but that's not quite it.

23
00:01:56,400 --> 00:01:58,410
‫How about if we look for falling?

24
00:01:58,410 --> 00:01:59,100
‫There you go.

25
00:01:59,100 --> 00:02:00,720
‫We've got an is falling.

26
00:02:00,720 --> 00:02:06,930
‫And if you click that, you can see that it automatically gets hold of the character movement component

27
00:02:06,930 --> 00:02:10,860
‫from that character to see whether we are falling or not.

28
00:02:11,310 --> 00:02:18,150
‫Then what we can do is we can pass that in to set the value of is airborne and obviously we're only

29
00:02:18,150 --> 00:02:22,200
‫going to be setting this if our cast to character succeeds.

30
00:02:22,200 --> 00:02:25,470
‫So let's hook in that execution pin right there.

31
00:02:25,860 --> 00:02:27,450
‫You can go ahead and compile that.

32
00:02:27,450 --> 00:02:31,590
‫Obviously, it's not going to change the preview, so we've got to go and try and play it.

33
00:02:31,590 --> 00:02:38,910
‫So let's play we jump and you can see we've got this falling variable instantly being true and that

34
00:02:38,910 --> 00:02:40,410
‫is working quite nicely actually.

35
00:02:40,410 --> 00:02:46,260
‫We were able to jump and land and jump and land and kill our enemies, obviously.

36
00:02:47,160 --> 00:02:51,960
‫So now I'd like to add a little bit more complication to our anim graph.

37
00:02:51,960 --> 00:02:56,340
‫So in the locomotion state machine at the moment, we've got two states here.

38
00:02:56,340 --> 00:03:02,820
‫But what I'd really like to do is to play a jumping animation, then an animation where we're airborne

39
00:03:02,820 --> 00:03:05,730
‫and then a landing animation when we hit the ground.

40
00:03:06,240 --> 00:03:09,570
‫To do that, we need some more states in our state machine.

41
00:03:09,570 --> 00:03:10,650
‫So let's go ahead.

42
00:03:10,650 --> 00:03:14,010
‫I'm going to do one of the set of states and you can do the final one.

43
00:03:14,460 --> 00:03:17,430
‫So the first one is going to be our jumping state.

44
00:03:18,560 --> 00:03:22,270
‫And that is going to play an animation that gets us off the ground.

45
00:03:22,280 --> 00:03:26,660
‫So let's go into the jumping state and to the output animation pose.

46
00:03:26,660 --> 00:03:28,400
‫We're going to link a new animation.

47
00:03:28,400 --> 00:03:29,270
‫We'll look for jump.

48
00:03:29,270 --> 00:03:32,210
‫We're looking for all the ones sub fixed with combat.

49
00:03:32,510 --> 00:03:35,450
‫So we're going to look for jump start combat.

50
00:03:35,450 --> 00:03:36,280
‫There you go.

51
00:03:36,290 --> 00:03:37,520
‫And that's what we want.

52
00:03:37,520 --> 00:03:43,010
‫Then we're going to go back to our locomotion state machine and we want to hook up some transitions.

53
00:03:43,010 --> 00:03:45,620
‫So we're going to transition from grounded to jumping.

54
00:03:45,740 --> 00:03:48,500
‫That's going to happen if we're airborne.

55
00:03:48,500 --> 00:03:52,100
‫So put in the air is airborne in there.

56
00:03:52,130 --> 00:03:55,670
‫Unfortunately, there's no way that I could see of changing the transition.

57
00:03:55,670 --> 00:04:00,200
‫So we're just going to have to delete the old transitions here in both cases.

58
00:04:00,560 --> 00:04:05,420
‫Then we're going to need a transition from jumping to is airborne, but we don't have a variable or

59
00:04:05,420 --> 00:04:06,380
‫state for that.

60
00:04:06,380 --> 00:04:09,830
‫So when is it that we're going to transition from jumping to his airborne?

61
00:04:09,830 --> 00:04:13,100
‫Well, we want to do it when the jumping animation has finished.

62
00:04:13,100 --> 00:04:17,060
‫When we've finished jumping, if you go and have a look at the jumping animation, you can see that

63
00:04:17,060 --> 00:04:20,240
‫it involves him lifting his feet off the ground like this.

64
00:04:20,240 --> 00:04:26,870
‫And so we want to basically transition into our apex animation when it's finished.

65
00:04:26,870 --> 00:04:29,540
‫Fortunately, there's an option for that in the transitions.

66
00:04:29,540 --> 00:04:34,070
‫If you select the transition rather than going into it, you can look at its details pane.

67
00:04:34,460 --> 00:04:36,020
‫And there's one option here.

68
00:04:36,810 --> 00:04:42,630
‫Which I expand out, says automatic rule based on sequence player in state.

69
00:04:42,900 --> 00:04:48,270
‫If you check that, basically what it's going to do is when we've nearly finished jumping, it's going

70
00:04:48,270 --> 00:04:53,460
‫to start transitioning into the next animation and you can actually control when that transition is

71
00:04:53,460 --> 00:04:54,900
‫and how long that crossfade is.

72
00:04:54,900 --> 00:05:01,320
‫Here in the blend settings, you can see the duration of the blend is about 0.2, but seeing as these

73
00:05:01,320 --> 00:05:06,330
‫two transitioning into each other particularly well, I'm going to make that 0.01.

74
00:05:06,330 --> 00:05:08,580
‫So I'm going to make that really short transition.

75
00:05:08,790 --> 00:05:10,560
‫So let's see what that looks like.

76
00:05:10,560 --> 00:05:12,150
‫So we're going to go into is airborne.

77
00:05:12,150 --> 00:05:16,710
‫It plays that jumping animation and then goes straight into the airborne state.

78
00:05:16,710 --> 00:05:18,090
‫Once the animation is finished.

79
00:05:18,090 --> 00:05:21,060
‫Let's try that one more time and we can try it one more time.

80
00:05:21,060 --> 00:05:27,270
‫That is the problem because we've got no transition out of the airborne state back to grounded and that

81
00:05:27,270 --> 00:05:29,040
‫is indeed going to be your challenge.

82
00:05:29,040 --> 00:05:33,450
‫So what you're going to do is add a landing state which is going to play a landing animation.

83
00:05:33,450 --> 00:05:36,720
‫So add the new state, add the animation that's most appropriate for landing.

84
00:05:36,720 --> 00:05:41,400
‫In your opinion, you might want to look for things with the jump prefix and the combat suffix.

85
00:05:41,580 --> 00:05:46,290
‫Then you're going to transition from airborne on a boolean into this landing state.

86
00:05:46,440 --> 00:05:51,810
‫And then from that landing state, you're going to transition to grounded when the landing animation

87
00:05:51,810 --> 00:05:52,920
‫has finished.

88
00:05:53,780 --> 00:05:55,940
‫Play it, play around, see how it feels.

89
00:05:55,970 --> 00:05:56,820
‫Does it feel good?

90
00:05:56,840 --> 00:05:58,070
‫Does it look right?

91
00:05:58,160 --> 00:06:04,520
‫And you may want to look at tweaking those transition times to see if that makes things feel better.

92
00:06:04,550 --> 00:06:08,450
‫Pause the video and have a go at playing around with our state machine.

93
00:06:10,560 --> 00:06:10,910
‫Okay.

94
00:06:10,920 --> 00:06:11,560
‫Welcome back.

95
00:06:11,580 --> 00:06:12,770
‫So let's give this a shot.

96
00:06:12,780 --> 00:06:14,790
‫We're going to add a new state in here.

97
00:06:14,820 --> 00:06:16,500
‫It's going to be called landing.

98
00:06:17,350 --> 00:06:21,390
‫And in this landing state, if we go in, we need an animation for it.

99
00:06:21,400 --> 00:06:29,110
‫I'm going to search for jump and what we want is jump land combat like so and then we can go back up

100
00:06:29,110 --> 00:06:30,730
‫to our locomotion state machine.

101
00:06:30,730 --> 00:06:33,820
‫We need a transition from airborne to landing.

102
00:06:33,820 --> 00:06:35,170
‫Let's double click on that.

103
00:06:35,170 --> 00:06:45,790
‫And this needs to be the not in not airborne basically so not node then the is airborne passed into

104
00:06:45,790 --> 00:06:46,390
‫that.

105
00:06:46,510 --> 00:06:48,580
‫So that's our transition condition.

106
00:06:48,580 --> 00:06:54,880
‫So when we're at the apex, once the not is airborne is unchecked, then we go into our landing state.

107
00:06:55,030 --> 00:06:59,110
‫Then from our landing state, we want to transition to grounded when finished.

108
00:06:59,110 --> 00:07:05,110
‫So if you click on the transition and check the automatic rule checkbox, it's going to do that when

109
00:07:05,110 --> 00:07:05,800
‫it's finished.

110
00:07:05,800 --> 00:07:06,940
‫So let's try that out.

111
00:07:06,940 --> 00:07:08,350
‫We're going to go into his airborne.

112
00:07:08,350 --> 00:07:12,280
‫It plays jumping, it goes into Airborne and then uncheck it.

113
00:07:12,280 --> 00:07:14,620
‫It goes to landing and back out.

114
00:07:14,710 --> 00:07:15,760
‫Let's do that again.

115
00:07:16,430 --> 00:07:17,600
‫Seems pretty good.

116
00:07:17,630 --> 00:07:18,080
‫Okay.

117
00:07:18,080 --> 00:07:24,300
‫So what we're going to do now is try playing it, jumping around and landing.

118
00:07:24,330 --> 00:07:24,680
‫Okay.

119
00:07:24,710 --> 00:07:26,030
‫This is feeling quite good.

120
00:07:26,060 --> 00:07:32,600
‫There's a little bit of lag when I'm landing between me landing and the running animation being played.

121
00:07:32,600 --> 00:07:38,750
‫So I'm going to click on the transition from landing to Grounded and have a look at our landing blend

122
00:07:38,750 --> 00:07:39,440
‫settings.

123
00:07:39,890 --> 00:07:43,220
‫Now we've got this duration of 0.1.

124
00:07:43,310 --> 00:07:48,650
‫That's how long it's taking us to do the transition and what's going on.

125
00:07:48,650 --> 00:07:53,360
‫So in our landing combat animation, how long is that landing?

126
00:07:53,360 --> 00:07:54,590
‫Combat animation?

127
00:07:54,620 --> 00:07:57,260
‫If I pause it, scroll along here.

128
00:07:57,350 --> 00:08:00,770
‫You can see that it is about 0.2.

129
00:08:00,770 --> 00:08:09,110
‫So it's actually taking the whole of that time and transitioning during that time in to our grounded

130
00:08:09,110 --> 00:08:10,040
‫locomotion.

131
00:08:10,040 --> 00:08:15,530
‫So that's kind of what we want because as soon as we've landed on the ground, as soon as the gameplay

132
00:08:15,530 --> 00:08:21,200
‫is telling us we've landed on the ground, we want to start showing some foot movement because otherwise

133
00:08:21,200 --> 00:08:22,820
‫it's going to look a little bit weird.

134
00:08:22,970 --> 00:08:29,600
‫So we want that transition to actually start happening as soon as possible, which is why we're playing

135
00:08:29,600 --> 00:08:35,120
‫very little of the landing animation and transitioning into the grounded one as much as quickly as possible.

136
00:08:35,150 --> 00:08:42,710
‫The only thing that we can really tweak here is the transition mode, which kind of dictates the shape

137
00:08:42,710 --> 00:08:48,890
‫of that curve as a shape of how much landing versus grounded we have over time.

138
00:08:48,890 --> 00:08:53,000
‫And you can test out various of these options, see which ones feel best for you.

139
00:08:53,030 --> 00:08:59,600
‫For me, it's the exponential out that feels best because that shows as much grounded as possible as

140
00:08:59,600 --> 00:09:02,460
‫early as possible, but without it feeling jarring.

141
00:09:02,480 --> 00:09:08,690
‫So if we now do is airborne and then go back to ground, you can see that it feels like it's going into

142
00:09:08,690 --> 00:09:12,210
‫grounded pretty quickly, which is what we want.

143
00:09:12,230 --> 00:09:16,520
‫So I'm going to go ahead and hit play and see if that feels better.

144
00:09:17,210 --> 00:09:21,290
‫Yeah, it feels a bit more responsive to me hitting the ground, which is exactly what I want.

145
00:09:21,440 --> 00:09:27,170
‫Now, in practice, if you had more animations here to work with, what you might want to do with the

146
00:09:27,170 --> 00:09:31,580
‫landed state is to have a blend space there and have a recovery animation.

147
00:09:31,580 --> 00:09:36,590
‫So depending how hard you hit the ground, you might hit you might play a recovery animation, which

148
00:09:36,590 --> 00:09:39,380
‫is blended depending on which direction you're moving in.

149
00:09:39,380 --> 00:09:44,600
‫So he would land with a hefty thud, but kind of stagger over to the left, for example.

150
00:09:44,630 --> 00:09:48,770
‫Now, that is not something that we're going to cover here just because we don't have the animations.

151
00:09:48,770 --> 00:09:51,090
‫But in theory, that's what you might do.

152
00:09:51,110 --> 00:09:58,130
‫So now one final kind of mini challenge for you is that we've currently got this blend poses by bool

153
00:09:58,160 --> 00:10:00,710
‫going on for our death animation.

154
00:10:00,800 --> 00:10:04,850
‫This could be done with a new state machine for death.

155
00:10:04,970 --> 00:10:12,260
‫See if you could try and refactor this anim graph so that it works with a state machine for death instead

156
00:10:12,260 --> 00:10:14,060
‫of this blend poses by bool.

157
00:10:14,300 --> 00:10:16,830
‫So hopefully you took me up on that challenge.

158
00:10:16,850 --> 00:10:23,510
‫What we're going to do is we're going to right click do a new state machine entirely new.

159
00:10:23,690 --> 00:10:29,690
‫We're going to rename this state machine to death or something similar like so then I'm going to go

160
00:10:29,690 --> 00:10:32,920
‫into that state machine and we're going to add two states.

161
00:10:32,930 --> 00:10:39,110
‫One is going to be the state alive and the other state is going to be dead.

162
00:10:40,160 --> 00:10:42,140
‫And then we're going to add some transitions.

163
00:10:42,140 --> 00:10:45,410
‫So transition from alive to dead, that is going to happen.

164
00:10:45,410 --> 00:10:50,840
‫If we double click, it's going to happen when is dead is true like so.

165
00:10:51,440 --> 00:10:58,970
‫And then we want a maybe we want a transition back to alive and we can just have that for testing purposes

166
00:10:58,970 --> 00:11:05,560
‫at least that's going to have a not boolean and it's going to have is dead so basically is not dead.

167
00:11:05,570 --> 00:11:07,550
‫We're going to go back the other way.

168
00:11:08,120 --> 00:11:10,460
‫We want to default to being in the alive state.

169
00:11:10,460 --> 00:11:11,210
‫That makes sense.

170
00:11:11,210 --> 00:11:12,980
‫And then we need some animations to play.

171
00:11:13,220 --> 00:11:15,650
‫So for Dead, we've already got that death animation.

172
00:11:15,650 --> 00:11:22,370
‫So I'm going to go in back up to the anim graph to cut that out, go back into the dead state and paste

173
00:11:22,370 --> 00:11:24,770
‫that death animation in here.

174
00:11:25,840 --> 00:11:27,220
‫Then in our live state.

175
00:11:27,220 --> 00:11:28,420
‫What do we want to play there?

176
00:11:28,450 --> 00:11:30,610
‫Well, actually, we want to play everything else.

177
00:11:30,620 --> 00:11:32,290
‫We want to play the aim of sets.

178
00:11:32,290 --> 00:11:33,930
‫We want to play the locomotion.

179
00:11:33,940 --> 00:11:35,800
‫So I'm going to cut all of that.

180
00:11:35,920 --> 00:11:37,600
‫And this is where it gets interesting.

181
00:11:37,600 --> 00:11:42,190
‫Now we've got a state machine running within a state machine, which is entirely possible.

182
00:11:42,190 --> 00:11:50,230
‫So we can then pipe in this aim of set into our output for the alive state and go back up to our anim

183
00:11:50,230 --> 00:11:56,710
‫graph entirely, remove all the nodes here and just pipe our death state machine into our output.

184
00:11:56,830 --> 00:12:00,370
‫And this works because we've got two top level states.

185
00:12:00,370 --> 00:12:02,590
‫Basically, we're saying they're either alive or dead.

186
00:12:03,040 --> 00:12:05,020
‫If you're dead, you just play a death animation.

187
00:12:05,020 --> 00:12:10,060
‫If you're alive, however, you do this aim offset and you do your locomotion state machine, which

188
00:12:10,060 --> 00:12:13,000
‫in turn has its own set of states.

189
00:12:13,000 --> 00:12:15,310
‫So it's layering state machine on top of state machine.

190
00:12:15,310 --> 00:12:17,650
‫Hopefully you see how that can be really powerful.

191
00:12:17,890 --> 00:12:22,030
‫So we can do now is dead, which overrides everything else that's running.

192
00:12:22,030 --> 00:12:25,810
‫It's no longer running the locomotion state machine because we're just playing that death animation.

193
00:12:25,870 --> 00:12:33,280
‫If I die as we go back to running the animation for a live but we can replay our death crucially, which

194
00:12:33,280 --> 00:12:34,600
‫previously we couldn't do.

195
00:12:34,600 --> 00:12:41,680
‫And that's because when you leave a state in an animation state machine, it resets the animation within

196
00:12:41,680 --> 00:12:43,060
‫it, it resets it to the beginning.

197
00:12:43,060 --> 00:12:45,700
‫So that's a really useful feature here for death.

198
00:12:45,700 --> 00:12:50,050
‫So to recap, what we've learnt about in this lecture is how to make more complex state machines and

199
00:12:50,330 --> 00:12:51,910
‫state machines within each other.

200
00:12:51,910 --> 00:12:57,880
‫And we've seen about automatic transitions and how they can help us make a sequence of transitions happen

201
00:12:57,880 --> 00:12:58,750
‫more easily.

202
00:12:58,750 --> 00:13:00,070
‫And I'll see you in the next lecture.

