﻿1
00:00:04,700 --> 00:00:05,570
‫Hello and welcome.

2
00:00:05,570 --> 00:00:10,820
‫In this lecture, we are going to be learning how to connect up our animations to our gameplay and we're

3
00:00:10,820 --> 00:00:17,270
‫going to get the speed of our character hooked up to the blend space so that we can get this effect.

4
00:00:17,270 --> 00:00:19,130
‫Let's dive in and see how it's done.

5
00:00:20,750 --> 00:00:21,140
‫Okay.

6
00:00:21,140 --> 00:00:27,950
‫So we have got ourselves a blend space to integrate in to this AVP shooter character.

7
00:00:28,400 --> 00:00:32,750
‫First thing I'm going to do is I'm going to go ahead and delete these two blends that we use as an example

8
00:00:32,750 --> 00:00:37,430
‫of how the animation blueprint anim graph works.

9
00:00:37,430 --> 00:00:43,610
‫And instead we're going to bring in from the asset browser in the bottom right, the blend space.

10
00:00:43,610 --> 00:00:46,670
‫So we've just created this BBS underscore locomotion.

11
00:00:46,700 --> 00:00:52,160
‫If you drag that in to your anim graph, you'll see it brings in this little green node here.

12
00:00:52,550 --> 00:00:59,870
‫And very much like the other blend nodes and things like that, we've got ourselves and an impose that

13
00:00:59,870 --> 00:01:02,450
‫we can drag into our output.

14
00:01:02,450 --> 00:01:09,800
‫And if I hit compile, you can see it's just in our default space and then you can see this little visualization

15
00:01:09,800 --> 00:01:17,330
‫which is quite handy of the little blend space and we could go ahead and change the values in here statically

16
00:01:17,330 --> 00:01:20,990
‫or we could input some variables into here.

17
00:01:21,860 --> 00:01:26,180
‫Well, we're probably going to want to do the latter, so I'm going to go ahead and delete the two variables

18
00:01:26,180 --> 00:01:32,960
‫we've got the left and the forward, because we know now that what we want is an angle which is going

19
00:01:32,960 --> 00:01:33,920
‫to be a float.

20
00:01:33,920 --> 00:01:39,710
‫So let's change that over to float and we're going to need a speed variable as well, which is also

21
00:01:39,710 --> 00:01:40,400
‫a float.

22
00:01:40,610 --> 00:01:47,210
‫And we can patch those two in the speed variable into the speed and the angle into the angle.

23
00:01:47,270 --> 00:01:53,450
‫And we'll go hit compile, look at our animate preview editor and just tweak the values.

24
00:01:53,450 --> 00:01:56,810
‫So first of all, the speed let's bring the speed up a little bit.

25
00:01:57,620 --> 00:02:01,640
‫Let's bring the speed up to about 30.

26
00:02:01,820 --> 00:02:02,600
‫See what happens.

27
00:02:02,600 --> 00:02:02,940
‫They go.

28
00:02:02,960 --> 00:02:05,990
‫He starts to walk by, bring it up to 70.

29
00:02:06,020 --> 00:02:08,030
‫He is getting closer to running.

30
00:02:08,030 --> 00:02:09,440
‫I bring it to 100.

31
00:02:09,740 --> 00:02:11,030
‫Well, not ten, 100.

32
00:02:11,030 --> 00:02:13,940
‫Then he's full on running and then we can change the angle.

33
00:02:13,940 --> 00:02:20,420
‫So at 90 degrees he's going 90 to the right, -90 is going mind going over to the left.

34
00:02:20,810 --> 00:02:21,890
‫We can go somewhere in between.

35
00:02:21,890 --> 00:02:23,120
‫So you can say 45 degrees.

36
00:02:23,120 --> 00:02:28,670
‫You can see he runs at a 45 degree angle and you can see the blend space where it is trying to pick

37
00:02:28,670 --> 00:02:30,800
‫in the blend space and what animations.

38
00:02:30,800 --> 00:02:36,380
‫It's sort of blending between it's blending between that forward animation and that 90 degrees right

39
00:02:36,380 --> 00:02:37,310
‫animation.

40
00:02:37,700 --> 00:02:39,230
‫So that's cool.

41
00:02:39,230 --> 00:02:40,550
‫We've got that going.

42
00:02:40,550 --> 00:02:47,270
‫But as we know, this needs to be driven by our actual gameplay and why do we do that anyway?

43
00:02:47,270 --> 00:02:54,110
‫Why don't we just have the animations drive our gameplay saying, you know, we need to be moving forward

44
00:02:54,110 --> 00:02:55,820
‫at such and such a pace?

45
00:02:56,120 --> 00:03:02,390
‫Well, the reason for not doing that, the reason for not using the animation to drive gameplay is that

46
00:03:02,390 --> 00:03:07,730
‫you often want your designer to be able to tweak all sorts of variables about your gameplay.

47
00:03:07,730 --> 00:03:12,830
‫You want them to be able to say, Okay, well, it doesn't feel right that this character is running

48
00:03:12,830 --> 00:03:13,340
‫at this speed.

49
00:03:13,340 --> 00:03:15,230
‫He needs to be running at this speed instead.

50
00:03:15,410 --> 00:03:17,990
‫And walking should be more at this speed.

51
00:03:18,320 --> 00:03:23,120
‫So you don't want your animations to constrain the design and game feel.

52
00:03:23,390 --> 00:03:28,190
‫You want the animations to come off the back of your game feel and make it look good.

53
00:03:28,190 --> 00:03:32,870
‫So during your design process, you might realize, actually we need a faster running animation and

54
00:03:32,870 --> 00:03:39,260
‫that's okay, but you want to be able to change up the game first to get there, rather than have to

55
00:03:39,290 --> 00:03:46,220
‫go and try and record a different running animation or find a different running animation and then realize

56
00:03:46,220 --> 00:03:48,250
‫that actually that didn't improve the feel of the game.

57
00:03:48,270 --> 00:03:51,320
‫That's why I want to keep these two things as separate as possible.

58
00:03:51,350 --> 00:03:57,320
‫There are times when things really must line up with the animations, but this is not one of them.

59
00:03:57,320 --> 00:03:59,990
‫So there are exceptions to every rule.

60
00:03:59,990 --> 00:04:04,040
‫So don't take this as a completely set in stone rule.

61
00:04:04,040 --> 00:04:09,830
‫You'll definitely see instances of games that drive some features from the animation, but generally

62
00:04:09,830 --> 00:04:12,170
‫speaking, we want to do it the other way around.

63
00:04:12,170 --> 00:04:16,010
‫We want to say, what's the speed of the character in the game?

64
00:04:16,010 --> 00:04:21,230
‫Let me go and update the speed of the animation rather than saying, What's the speed of the animation?

65
00:04:21,230 --> 00:04:23,240
‫Let me update the speed of the character in the game.

66
00:04:23,270 --> 00:04:23,510
‫Okay.

67
00:04:23,510 --> 00:04:26,090
‫With that said, how do we do this?

68
00:04:26,090 --> 00:04:32,360
‫Basically, the mechanics of it are that this blueprint, this animation blueprint, has an event graph

69
00:04:32,360 --> 00:04:38,330
‫like other blueprints do, which means that it can have things like a TIC event.

70
00:04:38,330 --> 00:04:44,810
‫If I go over in to the event graph and have a look, we have got a couple of event nodes in here that

71
00:04:44,810 --> 00:04:46,100
‫we can use to start from.

72
00:04:46,100 --> 00:04:48,740
‫We've got this blueprint update animation.

73
00:04:48,740 --> 00:04:56,360
‫If we come off of this every time it wants to update the animation, it's going to give us the execution

74
00:04:56,360 --> 00:04:59,840
‫node and allow us to go ahead and grab some state.

75
00:04:59,840 --> 00:05:05,000
‫So what we're going to do is every time this is called, we go and grab some state and notice here it's

76
00:05:05,000 --> 00:05:10,940
‫got this get spawn owner that's saying go ahead and get the pawn object.

77
00:05:10,940 --> 00:05:16,430
‫So let's remind ourselves the -- in this case is a character, character being a subclass of --

78
00:05:16,430 --> 00:05:19,130
‫and it would be this beep shooter character.

79
00:05:19,130 --> 00:05:20,780
‫Why would it be the beep shooter character?

80
00:05:20,780 --> 00:05:21,500
‫Well, let's see.

81
00:05:22,730 --> 00:05:27,320
‫Because this character, if we select the mesh, go to the viewport.

82
00:05:27,860 --> 00:05:33,350
‫It's currently running just a simple animation, but what we want to do is change the animation mode

83
00:05:33,350 --> 00:05:39,380
‫over to use animation blueprints and we want to use that app shooter character.

84
00:05:39,380 --> 00:05:42,530
‫So that is why this is the -- owner.

85
00:05:42,530 --> 00:05:44,810
‫It's using that animation blueprint.

86
00:05:44,810 --> 00:05:47,840
‫So the blueprint now has a pawn owner.

87
00:05:48,290 --> 00:05:54,770
‫And so what we want to do in this update function, just to summarize, is we want to grab the information

88
00:05:54,770 --> 00:05:57,020
‫from the pawn about its movement.

89
00:05:57,020 --> 00:05:59,030
‫We want to say, what's your speed?

90
00:05:59,030 --> 00:06:01,640
‫What's the angle of your movement?

91
00:06:01,970 --> 00:06:03,890
‫That's what we're going to calculate in this lecture.

92
00:06:03,890 --> 00:06:06,680
‫We're just going to do the speed because it's the simplest to do.

93
00:06:06,710 --> 00:06:11,900
‫The angle is going to require a little bit of manipulation with transforms, which we're going to look

94
00:06:11,900 --> 00:06:13,430
‫at in the next lecture.

95
00:06:13,430 --> 00:06:22,010
‫So the node that we're going to want here is to get the velocity of our pawn owner that gives us this

96
00:06:22,010 --> 00:06:23,000
‫vector here.

97
00:06:23,390 --> 00:06:29,850
‫And then off the back of that vector, we want to find its magnitude or its length so we can drag off

98
00:06:29,850 --> 00:06:33,290
‫of that vector search for the magnitude.

99
00:06:33,290 --> 00:06:37,790
‫And notice it's been clever here and I've searched for magnitude, but it's given me the function called

100
00:06:37,790 --> 00:06:38,450
‫vector length.

101
00:06:38,450 --> 00:06:42,470
‫So clearly magnitude they've clocked that it's a synonym for vector length.

102
00:06:42,470 --> 00:06:45,260
‫Why do we want to get the vector length rather than the vector itself?

103
00:06:45,260 --> 00:06:50,810
‫Because we're looking for a float, which is the speed vectors include the direction as well as the

104
00:06:50,810 --> 00:06:53,570
‫speed, which we're going to need to calculate the angle.

105
00:06:53,600 --> 00:06:57,080
‫But it isn't what we need to calculate the speed.

106
00:06:57,080 --> 00:06:59,060
‫So a little mini challenge for you here.

107
00:06:59,090 --> 00:06:59,750
‫Go ahead.

108
00:06:59,750 --> 00:07:02,510
‫There there isn't any other challenge in this lecture.

109
00:07:02,540 --> 00:07:06,920
‫Go ahead and set the speed using this vector length.

110
00:07:06,920 --> 00:07:09,020
‫And remember if you need any execution pin.

111
00:07:09,020 --> 00:07:11,750
‫We're trying to do this on the blueprint update animation.

112
00:07:11,750 --> 00:07:12,830
‫So pause the video and have a go.

113
00:07:12,860 --> 00:07:13,520
‫Okay, welcome back.

114
00:07:13,520 --> 00:07:16,160
‫So the speed is what we want to set.

115
00:07:16,160 --> 00:07:21,770
‫So if I drag that in to the blueprint and hit set speed, you can see we've got an execution pin that

116
00:07:21,770 --> 00:07:22,100
‫we need.

117
00:07:22,100 --> 00:07:27,950
‫We're going to get that from the Blueprint Update animation and we need the data pin, which is going

118
00:07:27,950 --> 00:07:32,060
‫to be the speed that comes from our vector length of getting our velocity.

119
00:07:32,240 --> 00:07:35,060
‫So it should be able to go ahead and save and compile that.

120
00:07:35,060 --> 00:07:40,250
‫You can see that's reset the speed to zero because now it's trying to set it from a pawn owner that

121
00:07:40,250 --> 00:07:42,080
‫is not really there.

122
00:07:42,740 --> 00:07:49,160
‫So what we're going to want to do is actually go ahead and play in the world and see what we've got.

123
00:07:49,400 --> 00:07:50,420
‫Okay, this is much better.

124
00:07:50,420 --> 00:07:56,090
‫We've got ourselves a pawn that's staying static on the ground, except for when I move, at which point

125
00:07:56,090 --> 00:07:58,700
‫it is giving me some speed.

126
00:07:59,270 --> 00:08:05,960
‫And if you use an analog input such as a controller, you can see that by changing the analog input

127
00:08:06,050 --> 00:08:07,580
‫that sort of changes the speed.

128
00:08:07,580 --> 00:08:12,590
‫We can change how fast this guy is moving.

129
00:08:14,580 --> 00:08:16,460
‫Now, obviously, there are two problems here.

130
00:08:16,470 --> 00:08:21,060
‫The first one being that if I move off an angle, it's just using the absolute speed.

131
00:08:21,060 --> 00:08:23,970
‫So it's not adjusting that angle in our blend space.

132
00:08:23,970 --> 00:08:25,830
‫And so the animation looks wrong.

133
00:08:26,220 --> 00:08:31,620
‫The other problem is that we're getting definitely some foot sliding here because the speed of our animation

134
00:08:31,620 --> 00:08:34,650
‫is not matching the speed of the character in our game.

135
00:08:34,680 --> 00:08:39,150
‫That's something that we will look at fixing in a following lecture as well.

136
00:08:39,330 --> 00:08:40,070
‫Great stuff.

137
00:08:40,080 --> 00:08:47,520
‫Hopefully you now understand how animations should hook up to gameplay using the animation blueprint

138
00:08:47,520 --> 00:08:51,920
‫and you should be able to go and apply that to your own game.

139
00:08:51,930 --> 00:08:58,020
‫See you in the next lecture where we will be hooking up those angles so that this movement looks a bit

140
00:08:58,020 --> 00:08:58,920
‫more natural.

