﻿1
00:00:04,500 --> 00:00:05,730
‫Hello and welcome to this lecture.

2
00:00:05,730 --> 00:00:11,310
‫We're going to be playing with AIM offsets that will allow our mesh to move its arms up and down.

3
00:00:11,310 --> 00:00:15,360
‫As we aim up and down, let's dive in and see what that's all about.

4
00:00:16,170 --> 00:00:20,940
‫So at the moment, if we aim up and down, you can see that our characters arms aren't actually doing

5
00:00:20,940 --> 00:00:26,370
‫anything and the gun is not really looking like it should be pointing up and firing and hitting the

6
00:00:26,370 --> 00:00:28,440
‫location that we're actually hitting.

7
00:00:28,710 --> 00:00:30,930
‫So how do we go about changing this?

8
00:00:30,930 --> 00:00:33,450
‫Well, it's a change to our animation blueprint.

9
00:00:33,450 --> 00:00:38,700
‫So let's go ahead and open up the animation blueprint as a starting point and dock it to our main window.

10
00:00:39,120 --> 00:00:44,250
‫And then I want to introduce you to a new type of animation asset that we haven't seen before.

11
00:00:44,250 --> 00:00:46,680
‫We've seen blend spaces, we've seen animations.

12
00:00:46,680 --> 00:00:53,160
‫The next thing that I want to show you is something called an animation offset and particularly an aim

13
00:00:53,160 --> 00:00:53,700
‫offset.

14
00:00:53,700 --> 00:01:00,060
‫So if we look for the keyword ayo in our animations, we're looking for these ones with a little blue

15
00:01:00,060 --> 00:01:02,130
‫underline called aim offsets.

16
00:01:02,130 --> 00:01:03,090
‫And there's a couple of them.

17
00:01:03,090 --> 00:01:09,180
‫The one I'm interested in is AoE combat, which should be around here somewhere.

18
00:01:09,180 --> 00:01:11,730
‫They would go a idle A0 combat.

19
00:01:11,970 --> 00:01:16,830
‫If you go and select that, then you'll see that we've got something looking a lot like our blend space.

20
00:01:16,860 --> 00:01:22,530
‫Except this time if you move the little green nubbin, what's going on is it's changing the direction

21
00:01:22,530 --> 00:01:25,680
‫that our characters mesh is pointing.

22
00:01:25,680 --> 00:01:30,720
‫So if we come over to the left, he points his gun to the left, we come over to the right, he points

23
00:01:30,720 --> 00:01:32,670
‫his gun to the right.

24
00:01:32,670 --> 00:01:36,250
‫And similarly with up and down, if you go pitch up, then he looks all the way up.

25
00:01:36,250 --> 00:01:39,240
‫He pitched down, he looks all the way down and tries to shoot down.

26
00:01:39,510 --> 00:01:46,680
‫Now the difference with this and other animations that we've seen is that this is known as an additive

27
00:01:46,680 --> 00:01:47,310
‫animation.

28
00:01:47,310 --> 00:01:51,750
‫If you go to the details pane, you can see that it's additive because it says additive settings and

29
00:01:51,750 --> 00:01:55,920
‫there's this animation based pose that it's basing all of this off.

30
00:01:56,340 --> 00:02:01,560
‫Basically what it means when it's additive is that this animation can be added on top of your other

31
00:02:01,560 --> 00:02:02,430
‫animations.

32
00:02:02,430 --> 00:02:06,090
‫So it's saying, I can do this aiming while you're running.

33
00:02:06,090 --> 00:02:13,320
‫I can add the information about where my arms have moved relative to your run pose and add them on top.

34
00:02:13,500 --> 00:02:14,700
‫So how does this look?

35
00:02:14,700 --> 00:02:22,200
‫If we go to our animation blueprint, what we want to do is add this information after we've added all

36
00:02:22,200 --> 00:02:28,050
‫this information about locomotion and probably not before death, because death should be the final

37
00:02:28,050 --> 00:02:28,530
‫thing.

38
00:02:29,040 --> 00:02:31,140
‫So we want to have the locomotion.

39
00:02:31,140 --> 00:02:32,970
‫So we've got all our running animation in there.

40
00:02:32,970 --> 00:02:39,390
‫We want to add on top of that the a little bit of information about where our arms should be moved so

41
00:02:39,390 --> 00:02:41,040
‫that we're aiming correctly.

42
00:02:41,130 --> 00:02:45,060
‫So to do this, we can right click and add in our aim offset.

43
00:02:45,060 --> 00:02:46,710
‫We can do it from the asset browser as well.

44
00:02:46,710 --> 00:02:52,380
‫I'm going to look for A0 and then as I said, we're looking for that combat version, which is a different

45
00:02:52,380 --> 00:02:53,580
‫place in this browser.

46
00:02:53,580 --> 00:03:00,180
‫Funnily enough, if I track that in, then what you get is something with an input pin which says What's

47
00:03:00,180 --> 00:03:01,140
‫the base powered?

48
00:03:01,170 --> 00:03:07,050
‫Notice that locomotion blend space didn't have an input pin because it's supplying you the whole animation,

49
00:03:07,140 --> 00:03:14,580
‫whereas this aim offset because it's an additive animation, it requires something to add on top of.

50
00:03:14,580 --> 00:03:20,040
‫So you need to give it a base pose which is going to come from our locomotion, and then we're going

51
00:03:20,040 --> 00:03:26,700
‫to go and input that into our false pose of the blend, whether we are dead or not, because we're only

52
00:03:26,700 --> 00:03:28,260
‫showing this if we're not dead.

53
00:03:29,000 --> 00:03:36,770
‫And then I want to show you that if I were to change the pitch to one or maybe to 180, actually, and

54
00:03:36,770 --> 00:03:41,750
‫go ahead and compile, then you can see that he's fully looking upwards.

55
00:03:41,900 --> 00:03:44,570
‫Now, another tweak I want to do here is in the event graph.

56
00:03:44,570 --> 00:03:50,120
‫At the moment, we've got a rather vexing situation where we can't tweak anything in the anim preview

57
00:03:50,120 --> 00:03:54,890
‫because it's being overwritten with zeros by our event graph.

58
00:03:54,890 --> 00:04:01,850
‫An easy way to fix this is to simply put a check in here for whether the pawn owner that we've got here

59
00:04:02,000 --> 00:04:04,370
‫is valid, namely is it null?

60
00:04:04,820 --> 00:04:10,280
‫So if we put an is valid here and the one with the question mark automatically gives us these execution

61
00:04:10,280 --> 00:04:18,140
‫nodes and if we pass through our update animation execution node and only set things if that's valid,

62
00:04:18,170 --> 00:04:23,750
‫then what's going to happen is that when you are not actually playing and there isn't a pawn there to

63
00:04:23,750 --> 00:04:26,960
‫give us the information, it's going to allow us to set it in.

64
00:04:26,960 --> 00:04:28,470
‫The Anim Preview Editor.

65
00:04:28,490 --> 00:04:36,620
‫So now I can change the speed and you can see that he starts running with his aim offset set up high.

66
00:04:36,860 --> 00:04:41,090
‫So let's set this so that our pitch is actually a variable here.

67
00:04:41,090 --> 00:04:47,120
‫So I'm going to right click on pitch and promote the variable and bring that variable down here where

68
00:04:47,120 --> 00:04:50,510
‫it's visible and change its name to pitch.

69
00:04:51,110 --> 00:04:54,530
‫Or in fact, let's be more specific, this is the aim pitch like.

70
00:04:54,530 --> 00:05:00,290
‫So now if we go ahead and compile, we set a default aim pitch by accident.

71
00:05:00,290 --> 00:05:03,380
‫We want to set that down to zero by default.

72
00:05:03,560 --> 00:05:05,150
‫I'm going to go ahead and compile that.

73
00:05:05,150 --> 00:05:11,270
‫And now if we go ahead and change the speed and then change the aim pitch.

74
00:05:12,110 --> 00:05:17,090
‫You can see we can aim up and we can aim down, which is exactly what we want.

75
00:05:17,120 --> 00:05:20,180
‫Now, the problem here is it's not being set in our game just yet.

76
00:05:20,180 --> 00:05:26,930
‫If we go up and down, none of that is coming from information from our control rotation and our aiming.

77
00:05:27,020 --> 00:05:31,040
‫So we need to go back to our event graph and get some of that information in here.

78
00:05:31,070 --> 00:05:36,050
‫Now, I'm just going to space things out a little bit here because this is getting rather long.

79
00:05:36,050 --> 00:05:42,680
‫And what I want to do is off this valid pin is I want to put a sequence node which is going to let me

80
00:05:42,770 --> 00:05:47,720
‫spread things out a little bit down the in the vertical direction as well.

81
00:05:47,720 --> 00:05:53,030
‫So the sequence node, first of all, is going to go off to setting the speed and angle over here.

82
00:05:53,030 --> 00:05:57,290
‫Then I think we can move this stuff to do with casting to the shooter character.

83
00:05:57,380 --> 00:06:04,610
‫I think we can bring this down further vertically, hooking up that sequence pin and the object pin

84
00:06:04,610 --> 00:06:09,860
‫to our try get pawn owner node, then we can add another pin into the sequence.

85
00:06:09,860 --> 00:06:13,820
‫And this time I want to get two pieces of information from our pawn owner.

86
00:06:13,940 --> 00:06:17,330
‫The first one is going to be our control rotation.

87
00:06:17,330 --> 00:06:20,060
‫So let's do a get control rotation.

88
00:06:20,360 --> 00:06:26,360
‫But this isn't going to be enough because our control rotation, if we split the pin, you can see we've

89
00:06:26,360 --> 00:06:29,570
‫got a pitch in here and we could try setting that pitch.

90
00:06:29,570 --> 00:06:30,950
‫Let's let's give that a go.

91
00:06:30,980 --> 00:06:38,570
‫So if I do a set pitch and connect up the execution node to the execution node from our sequence, adding

92
00:06:38,570 --> 00:06:44,960
‫in a bit of a redirect to there, what's going to happen if we compile, save, hit play and then aim

93
00:06:44,960 --> 00:06:46,320
‫up works fine.

94
00:06:46,340 --> 00:06:48,800
‫Aim down does not turn around.

95
00:06:48,800 --> 00:06:52,310
‫Then things start to look even more weird.

96
00:06:52,400 --> 00:06:59,330
‫Now what's going on there is that this control rotation is entirely global and so doesn't take into

97
00:06:59,330 --> 00:07:02,870
‫account the direction that our player is already facing.

98
00:07:02,930 --> 00:07:10,910
‫So to take that into account, we need to go to the pawn again and get the actor rotation.

99
00:07:10,910 --> 00:07:18,560
‫And then what we want to find is the rotation between the actor's rotation to the control rotation.

100
00:07:18,560 --> 00:07:22,640
‫And the way we do this is I'm just going to disconnect the AM pitch.

101
00:07:22,940 --> 00:07:28,730
‫Break that link and right click and recombine the struct pins is I want to do a delta between those

102
00:07:28,730 --> 00:07:33,470
‫two so I can take off of the control rotation and look for Delta.

103
00:07:34,240 --> 00:07:41,280
‫And Delta is basically a fancy way of saying subtraction between rotators.

104
00:07:41,290 --> 00:07:48,820
‫So what we want to do is take our control rotation and subtract the base rotation, which is going to

105
00:07:48,820 --> 00:07:50,830
‫be our actor rotation.

106
00:07:50,830 --> 00:07:55,930
‫So that's B so it's going to be A minus B if you hover over, that's what the Delta rotator does.

107
00:07:56,050 --> 00:08:01,660
‫And we basically want to be saying, Yeah, I want the control rotation, but take away all that information

108
00:08:01,660 --> 00:08:03,610
‫about our active rotation.

109
00:08:03,610 --> 00:08:10,270
‫So I can just know whether we're aiming up and down relative to the direction that our character is

110
00:08:10,270 --> 00:08:10,960
‫facing.

111
00:08:11,110 --> 00:08:17,830
‫And then if I split out the return value pin from that and use the pitch from there, we're going to

112
00:08:17,830 --> 00:08:20,170
‫see that everything works as expected.

113
00:08:20,170 --> 00:08:26,950
‫When I look up my naming up, when I look down, I'm aiming down and doesn't matter which way I'm facing

114
00:08:26,950 --> 00:08:29,440
‫in the world, that's always going to be the case.

115
00:08:29,440 --> 00:08:33,220
‫So that's almost it for our aim rotation.

116
00:08:33,220 --> 00:08:38,350
‫The only problem is that at the moment our eye is incapable of aiming like this.

117
00:08:38,350 --> 00:08:46,660
‫So if I go and put a shooter character up on the stairs over here and then we go over to try and hound

118
00:08:46,660 --> 00:08:49,420
‫him down, try and get him to come over to us.

119
00:08:49,420 --> 00:08:50,500
‫Here he comes.

120
00:08:50,500 --> 00:08:53,350
‫You can see that he's just shooting off into the wall.

121
00:08:53,350 --> 00:08:56,200
‫He's not trying to aim at all, which is a bit sad.

122
00:08:56,200 --> 00:08:57,670
‫So what's going on there?

123
00:08:57,670 --> 00:09:04,120
‫If we go to our eye and our behavior tree, you can see that we're setting a default focus to a location.

124
00:09:04,120 --> 00:09:10,210
‫And by default, if you set a focus to a location, then Unreal is not going to update your control

125
00:09:10,210 --> 00:09:13,540
‫rotation in the same way it's not going to do the pitch.

126
00:09:13,720 --> 00:09:15,100
‫So that's a bit sad.

127
00:09:15,100 --> 00:09:21,970
‫Okay, so what we need to do is go to a blackboard and change this player location to just be a reference

128
00:09:21,970 --> 00:09:23,680
‫to the player instead.

129
00:09:24,060 --> 00:09:27,790
‫Then we need to change this vector over to be an object.

130
00:09:27,790 --> 00:09:33,430
‫So now what we've got is a blackboard key for the player, which is an object, and we can change the

131
00:09:33,430 --> 00:09:38,860
‫base class to b actor if we want to, although it's not particularly important.

132
00:09:38,860 --> 00:09:44,620
‫And then what that means is over in the behavior tree, we can switch things up so that we are moving

133
00:09:44,620 --> 00:09:49,570
‫to instead of moving to our player location, we're moving to the player actor.

134
00:09:49,570 --> 00:09:55,330
‫We can set the focus to be the player actor and update the player.

135
00:09:55,330 --> 00:10:00,400
‫Location of scene now needs to be pointing to a player actor as well.

136
00:10:00,400 --> 00:10:05,860
‫Now, this isn't going to work just yet because our update player location of scene is currently trying

137
00:10:05,860 --> 00:10:08,260
‫to set a location into this key.

138
00:10:08,260 --> 00:10:11,050
‫So a little mini challenge for you, see if you can update it.

139
00:10:11,050 --> 00:10:18,810
‫So instead of setting the location in that behavior tree service, we're setting the actual actor pause

140
00:10:18,820 --> 00:10:19,720
‫video and have a go.

141
00:10:19,750 --> 00:10:20,650
‫Okay, welcome back.

142
00:10:20,650 --> 00:10:25,810
‫So we're going to go over in to Visual Studio code and look for our service particularly.

143
00:10:25,810 --> 00:10:29,650
‫It's the service underscore player location if seen.

144
00:10:29,800 --> 00:10:35,830
‫And we're going to change this to instead of set value as vector, it's going to be set value as object,

145
00:10:36,280 --> 00:10:37,090
‫simple as that.

146
00:10:37,090 --> 00:10:42,190
‫We had the choices of types in the blackboard, and that's what we're going to tell it here.

147
00:10:42,220 --> 00:10:46,360
‫Now, obviously, it's going to complain that what we're trying to set is a vector rather than an object.

148
00:10:46,360 --> 00:10:51,280
‫So we're going to just remove the get actor location and pass in the player pawn.

149
00:10:51,280 --> 00:10:56,860
‫Instead, clearing the value is the same as it was before, so we can just go back into the editor,

150
00:10:56,890 --> 00:11:03,340
‫hit, compile, and see if this new set up is working with aiming for the I Kate let's dive in hit play.

151
00:11:03,370 --> 00:11:05,800
‫Go and find out I up on the stairs.

152
00:11:06,590 --> 00:11:13,250
‫Get them to try and come and look down as come on I and one more thing that I've forgotten from the

153
00:11:13,250 --> 00:11:19,820
‫behaviour tree to update is the cansee player at the moment is has gone on reset the blackboard key

154
00:11:19,820 --> 00:11:26,600
‫to self actor we want to that to be player basically is the player set let's go and make that change

155
00:11:26,600 --> 00:11:31,700
‫because at the moment the I wasn't coming to chase us now it's chasing us and in fact if you jump,

156
00:11:31,730 --> 00:11:36,050
‫you can just about see that the aim rotation of this guy is changing.

157
00:11:36,050 --> 00:11:40,550
‫Let's go over to the stairs and see whether he can shoot down from the stairs at us.

158
00:11:41,030 --> 00:11:41,690
‫Excellent.

159
00:11:41,690 --> 00:11:46,130
‫He's changed his rotation and indeed he is shooting right at us.

160
00:11:46,130 --> 00:11:47,300
‫Both of them are where?

161
00:11:47,300 --> 00:11:49,250
‫So I'm losing health and will soon die.

162
00:11:50,600 --> 00:11:57,080
‫Okay, that's it for this lecture we have added in an aim offset and we have updated our eye so that

163
00:11:57,080 --> 00:11:59,150
‫it can use that to aim as well.

164
00:11:59,180 --> 00:12:03,410
‫The next lecture we're going to be doing something about this funny running while in the air.

165
00:12:03,410 --> 00:12:04,370
‫I will see you there.

