﻿1
00:00:04,410 --> 00:00:04,750
‫Hello.

2
00:00:04,780 --> 00:00:05,160
‫Welcome.

3
00:00:05,160 --> 00:00:09,090
‫In this lecture, we're going to be adding in controller movement so that we can move around using a

4
00:00:09,090 --> 00:00:12,030
‫controller, which is what you're seeing going on right here.

5
00:00:12,060 --> 00:00:18,090
‫I'm going to do this using a different set of axes for look up rate and look right rate, and we'll

6
00:00:18,090 --> 00:00:19,500
‫see why that is necessary.

7
00:00:19,500 --> 00:00:21,300
‫Let's dive in and find out why.

8
00:00:23,140 --> 00:00:26,410
‫So I want to be able to move around our scene using the controller.

9
00:00:26,410 --> 00:00:30,520
‫I can already do this when I am not in play mode.

10
00:00:30,760 --> 00:00:36,340
‫So we want to be able to do the same sort of movement as this with panning with the right stick and

11
00:00:36,340 --> 00:00:40,840
‫with moving around left and right with our left stick.

12
00:00:41,050 --> 00:00:42,820
‫And we can also go up and down.

13
00:00:43,060 --> 00:00:47,340
‫But that's not something that our opponent is going to be able to do, because it's not a flying pawn.

14
00:00:47,350 --> 00:00:53,340
‫So what we're going to want to do is, first of all, it's easy to map the movement.

15
00:00:53,350 --> 00:00:59,920
‫All we have to do is go to our project settings, go down to wherever input is, engine input, and

16
00:00:59,920 --> 00:01:03,640
‫we've got our move forward axis and we've also got our move right axis.

17
00:01:03,640 --> 00:01:10,690
‫And that's pretty straightforward to add in yet another mapping as well as W and S, we can add in our

18
00:01:10,690 --> 00:01:11,770
‫gamepad.

19
00:01:11,800 --> 00:01:17,380
‫If we look under gamepad, you can see the left thumbstick we want the y axis for moving forward.

20
00:01:17,380 --> 00:01:23,830
‫For the moving right, we're going to add the again the gamepad and it's the gamepad, still the left

21
00:01:23,830 --> 00:01:24,190
‫stick.

22
00:01:24,190 --> 00:01:29,140
‫But this time we're doing x and y axis and we can see whether that is the right sort of movement.

23
00:01:29,140 --> 00:01:31,330
‫So go ahead and hit play.

24
00:01:31,360 --> 00:01:33,250
‫I use alt p as my shortcut for that.

25
00:01:33,250 --> 00:01:37,570
‫Then left and right works forward and backwards works as we would expect.

26
00:01:37,570 --> 00:01:41,740
‫But obviously turning doesn't work because we haven't mapped that yet.

27
00:01:41,740 --> 00:01:43,000
‫So let's give that a shot.

28
00:01:43,000 --> 00:01:48,790
‫If we go to settings, project settings and input again, let's have a look, look up.

29
00:01:48,790 --> 00:01:50,350
‫We currently using the mouse y.

30
00:01:50,380 --> 00:01:53,380
‫What would be wrong with just adding in here?

31
00:01:53,380 --> 00:01:58,330
‫For example, the gamepad, the right stick, and this time the y axis?

32
00:01:58,630 --> 00:02:02,440
‫Well, on first attempt we can go and have a little play.

33
00:02:02,470 --> 00:02:04,930
‫This might actually seem to be okay.

34
00:02:04,930 --> 00:02:07,510
‫So we go in and you can see we can move around.

35
00:02:07,510 --> 00:02:07,960
‫Yeah, sure.

36
00:02:07,960 --> 00:02:10,630
‫It's a little bit fast, but it's kind of okay, isn't it?

37
00:02:10,660 --> 00:02:11,880
‫Isn't that okay?

38
00:02:11,890 --> 00:02:13,690
‫Well, not really.

39
00:02:15,200 --> 00:02:20,810
‫And the reason ultimately boils down to frame rates and how these axes work.

40
00:02:21,380 --> 00:02:27,860
‫So what happens with a mouse when we're running a game at 30 frames per second, when we move our mouse

41
00:02:27,860 --> 00:02:33,920
‫from left to right across the screen at a kind of even speed, we might see that the axes values are

42
00:02:33,920 --> 00:02:36,560
‫something like ten, then ten, then ten.

43
00:02:36,560 --> 00:02:42,830
‫And this is telling us that each time the mouse has moved by ten units to the right and it's done it

44
00:02:42,830 --> 00:02:44,420
‫the same every frame.

45
00:02:45,080 --> 00:02:47,890
‫What happens if we double our frame rate?

46
00:02:47,900 --> 00:02:52,700
‫Well, suddenly the mouse is still moving at the same rate because the player is still moving their

47
00:02:52,700 --> 00:02:54,170
‫hand at the same speed.

48
00:02:54,170 --> 00:02:59,840
‫But because we're showing frames more often, we're having ticks more often, then what's going to happen

49
00:02:59,840 --> 00:03:05,060
‫is the input from the axes is actually going to be halved each time we're going to get a five of five

50
00:03:05,060 --> 00:03:06,290
‫or five of five or five.

51
00:03:06,650 --> 00:03:12,710
‫So great, that's fine, because that means that we're still going to be panning across our screen at

52
00:03:12,710 --> 00:03:18,200
‫the same rate, no matter whether we have a fast computer or a slow computer.

53
00:03:18,470 --> 00:03:24,740
‫If we move our mouse by a certain amount, you're going to notice the same amount of movement, which

54
00:03:24,740 --> 00:03:25,580
‫is what we want.

55
00:03:25,610 --> 00:03:31,940
‫Now things change a little bit when we look at the controller, say we go full throttle to the right

56
00:03:31,940 --> 00:03:36,380
‫with our analog controller and it's at 30 frames a second.

57
00:03:36,380 --> 00:03:38,780
‫We get one, then one, then one.

58
00:03:38,780 --> 00:03:39,950
‫Makes sense, right?

59
00:03:40,250 --> 00:03:42,380
‫What about if it's at 60 frames per second?

60
00:03:42,410 --> 00:03:44,720
‫We still get one, then one, then one, then one.

61
00:03:44,720 --> 00:03:47,360
‫But we get more of them because we're getting more frames.

62
00:03:47,570 --> 00:03:54,920
‫If you use that directly to affect the movement of your pawn, you're going to see that it moves at

63
00:03:54,920 --> 00:03:59,390
‫twice the speed, at twice the frame rate, not what we want.

64
00:03:59,390 --> 00:04:03,740
‫So what we want to do is introduce some frame rate independence here.

65
00:04:03,980 --> 00:04:09,650
‫So to do this, we need to be able to multiply by the delta time.

66
00:04:09,650 --> 00:04:15,560
‫We kind of want to use the input axis to help us modulate the rotation speed.

67
00:04:16,160 --> 00:04:18,350
‫So that's a little bit to take in there.

68
00:04:18,350 --> 00:04:22,850
‫But what I mean is that we need to have something like a rotation rate variable.

69
00:04:22,850 --> 00:04:29,300
‫We're going to create a new property for that, which is going to be an edit anywhere and we are going

70
00:04:29,300 --> 00:04:34,820
‫to have it be a float and it's going to be the rotation rate.

71
00:04:34,820 --> 00:04:40,160
‫Now I'm going to use the same rotation rate for both up and left and right.

72
00:04:40,160 --> 00:04:43,130
‫You can go ahead and have a separate variable for both of those.

73
00:04:43,130 --> 00:04:46,460
‫And I don't really know what a good rotation rate is going to be here.

74
00:04:46,460 --> 00:04:48,400
‫I'm just going to give a flying gas hex.

75
00:04:48,410 --> 00:04:53,330
‫I'm not sure what the units involved are here at all, so I'm just going to go ahead and say ten.

76
00:04:53,330 --> 00:04:54,020
‫But we'll see.

77
00:04:54,020 --> 00:04:55,610
‫Maybe that's way too fast.

78
00:04:55,610 --> 00:04:56,750
‫Maybe that's way too slow.

79
00:04:56,750 --> 00:05:01,760
‫We can adjust that in our blueprint so we can go ahead and save that.

80
00:05:01,760 --> 00:05:07,400
‫I'm going to go over to the C++ Alt O to switch the C++, by the way, and we're going to want to have

81
00:05:07,400 --> 00:05:11,300
‫a new type of axis so that we can distinguish between the move.

82
00:05:11,300 --> 00:05:15,020
‫Right, which is the mouse, a direct movement versus the move.

83
00:05:15,020 --> 00:05:15,440
‫Right?

84
00:05:15,440 --> 00:05:16,550
‫Or rather sorry, the look.

85
00:05:16,550 --> 00:05:18,860
‫Right, which is the rate.

86
00:05:19,370 --> 00:05:25,820
‫So we're going to do that by going over to our project settings and instead of having this gamepad left

87
00:05:25,820 --> 00:05:27,740
‫thumbstick mapped to the move.

88
00:05:27,740 --> 00:05:31,880
‫Right, sorry, not the left thumbstick, but the right one mapped to look up.

89
00:05:31,880 --> 00:05:37,970
‫I keep making that mistake, remove that from that axis and add a new axis which is going to be the

90
00:05:37,970 --> 00:05:38,870
‫look.

91
00:05:39,920 --> 00:05:40,550
‫Up.

92
00:05:40,970 --> 00:05:41,770
‫Right.

93
00:05:42,110 --> 00:05:45,680
‫And this is going to take in our gamepad, right?

94
00:05:45,680 --> 00:05:47,420
‫So a gamepad, right.

95
00:05:47,720 --> 00:05:53,780
‫Y axis because it's a look up and we're saying that positive one should be the one that we're using.

96
00:05:54,200 --> 00:06:00,230
‫So then what we can do is we need to map this and we don't want to map it directly to the ad controller.

97
00:06:00,230 --> 00:06:05,120
‫Your because we need to do a little bit of maths to calculate the rates and make those rates frame rate

98
00:06:05,120 --> 00:06:05,900
‫independent.

99
00:06:05,900 --> 00:06:11,900
‫So what we're going to do is go over to alt zero and create ourselves a look up, which handily we've

100
00:06:11,900 --> 00:06:12,950
‫already got here.

101
00:06:12,950 --> 00:06:19,010
‫And I'm going to create it as look up right and go ahead and create this control shift.

102
00:06:19,010 --> 00:06:22,210
‫P And I'm using my implementation plug in.

103
00:06:22,220 --> 00:06:25,730
‫Let's go ahead and do a look up rate implementation.

104
00:06:26,630 --> 00:06:27,950
‫Got an axis value coming in.

105
00:06:27,950 --> 00:06:28,640
‫That's great.

106
00:06:28,640 --> 00:06:34,100
‫We then want to make sure that's what we're calling in set up player input component.

107
00:06:34,100 --> 00:06:37,010
‫So let's create a new line here, duplicate the look.

108
00:06:37,010 --> 00:06:38,780
‫Right, I'm going to call it look up.

109
00:06:38,780 --> 00:06:42,920
‫Right, like so and then copy and paste the.

110
00:06:43,670 --> 00:06:49,040
‫Fully qualified reference to the function to call our look up rate.

111
00:06:49,790 --> 00:06:56,570
‫Then essentially what we want to be calling at the end of the day is add controller input, pitch,

112
00:06:56,570 --> 00:06:57,950
‫controller, pitch input.

113
00:06:58,460 --> 00:07:00,860
‫But we want to multiply this by a couple of things.

114
00:07:00,860 --> 00:07:04,580
‫So our access value comes in as a value between zero and one.

115
00:07:04,940 --> 00:07:12,020
‫If we multiply that so axis value multiplied by the rate rotation rate.

116
00:07:12,870 --> 00:07:17,610
‫Then what we're going to get is a speed, but what we want is actually a distance.

117
00:07:17,610 --> 00:07:20,700
‫Like when we moved our mouse, we moved at a certain distance, every frame.

118
00:07:20,700 --> 00:07:22,050
‫That's what was coming in.

119
00:07:22,050 --> 00:07:24,630
‫We want to convert this speed to distance.

120
00:07:24,630 --> 00:07:30,750
‫And if you remember some way back in, some hazy math class, to get from speed to distance, we need

121
00:07:30,750 --> 00:07:32,850
‫to multiply by the amount of time.

122
00:07:32,850 --> 00:07:37,620
‫So we do that by getting our Delta seconds from the world.

123
00:07:37,620 --> 00:07:39,540
‫Now what is Delta seconds?

124
00:07:39,540 --> 00:07:43,050
‫That is the amount of time that it took for the last frame.

125
00:07:43,050 --> 00:07:45,600
‫So it's kind of the opposite of the frame rate.

126
00:07:45,600 --> 00:07:50,430
‫It's telling us how long a frame takes, which is great because that is the amount of time that we need

127
00:07:50,430 --> 00:07:51,900
‫to apply this movement over.

128
00:07:51,900 --> 00:07:56,700
‫So if you think about it, we've got a speed, we've got an amount of time that we need to apply that

129
00:07:56,700 --> 00:07:57,840
‫speed over.

130
00:07:57,870 --> 00:08:03,990
‫It gives us an amount of movement that we essentially want to apply to our controller pitch input.

131
00:08:03,990 --> 00:08:05,040
‫So that's what we want.

132
00:08:05,070 --> 00:08:11,130
‫Get World first of all, because we want to get the level, we'll get the world around us.

133
00:08:11,130 --> 00:08:20,310
‫And then from that we use the arrow function to do get Delta seconds, which tells us that we want to

134
00:08:20,310 --> 00:08:26,100
‫get the amount of time that elapsed in the last frame, which gives us again this approximation of our

135
00:08:26,100 --> 00:08:28,470
‫frame rate at the current moment in time.

136
00:08:28,470 --> 00:08:34,260
‫Now you might be wondering why we're not doing the same with the movement input, and the reason is

137
00:08:34,260 --> 00:08:39,780
‫that the movement input, when you do an ad input there, it's already supposing that that's a rate,

138
00:08:39,810 --> 00:08:42,900
‫not an actual amount of movement.

139
00:08:42,900 --> 00:08:49,200
‫So it's already doing this calculation for us, essentially under the hood, save up the files, go

140
00:08:49,200 --> 00:08:53,610
‫over into unreal and compile and see whether any of this is worth it.

141
00:08:55,390 --> 00:09:01,420
‫So let's head on into play and I'm going to try and use my controller input.

142
00:09:01,450 --> 00:09:02,020
‫There we go.

143
00:09:02,050 --> 00:09:04,840
‫We're going up and down rather slowly.

144
00:09:04,960 --> 00:09:10,900
‫But hopefully this will be completely frame rate independent because we've used that delta time.

145
00:09:11,650 --> 00:09:18,530
‫So what I want you to do is to go ahead and implement the look right rate.

146
00:09:18,550 --> 00:09:25,000
‫So repeat the same method set up for looking right as he did for looking up and tweak the speed so that

147
00:09:25,000 --> 00:09:30,310
‫it doesn't go really slow and you can actually use it to move around the level, pause the video and

148
00:09:30,310 --> 00:09:30,910
‫have a go.

149
00:09:32,400 --> 00:09:32,850
‫Okay.

150
00:09:32,850 --> 00:09:33,600
‫Welcome back.

151
00:09:33,630 --> 00:09:39,070
‫So first step was we went and created a new axis mapping in our project settings.

152
00:09:39,070 --> 00:09:42,840
‫We're going to have to do that again, this time for the look.

153
00:09:42,840 --> 00:09:43,500
‫Right?

154
00:09:43,500 --> 00:09:44,310
‫Right.

155
00:09:44,340 --> 00:09:46,010
‫Like so what a mouthful.

156
00:09:46,020 --> 00:09:49,620
‫Then we're going to go and get the gamepad.

157
00:09:50,300 --> 00:09:54,440
‫The right this time and the x axis, that's the one we're going to be mapping.

158
00:09:55,310 --> 00:09:59,960
‫And then we're going to go over to our shooter header file this time.

159
00:10:00,320 --> 00:10:02,870
‫We're going to duplicate the look up rate.

160
00:10:03,060 --> 00:10:07,390
‫And let me just show you the files so you can see where I am over on the left hand side.

161
00:10:07,400 --> 00:10:12,110
‫So we're going to have instead of the look up rate, it's going to be the look right rate control shift

162
00:10:12,110 --> 00:10:19,640
‫p create implementation and we're going to have pretty much exactly the same code with the same multiplication

163
00:10:19,640 --> 00:10:26,150
‫that is getting us from, again, a speed to a amount of distance moved.

164
00:10:26,810 --> 00:10:27,320
‫That's the look.

165
00:10:27,320 --> 00:10:27,920
‫Right, right.

166
00:10:27,920 --> 00:10:34,940
‫So instead of doing the add controller pitch, we need to do the your input this time and the look right

167
00:10:34,940 --> 00:10:41,210
‫rate is going to need to be called from our set player input component or it needs to be called when

168
00:10:41,210 --> 00:10:43,990
‫the axis is actually being manipulated.

169
00:10:44,000 --> 00:10:47,620
‫So we're going to add another axis in here instead of look up rate.

170
00:10:47,630 --> 00:10:49,910
‫It's going to be the look right rate.

171
00:10:50,240 --> 00:10:57,290
‫And then so we're going to want to copy that reference to the function, remembering the ampersand before

172
00:10:57,290 --> 00:10:59,180
‫and then the fully qualified issue to character.

173
00:10:59,180 --> 00:10:59,480
‫Colon.

174
00:10:59,480 --> 00:11:01,610
‫Colon, look right rate.

175
00:11:01,610 --> 00:11:04,070
‫Let's go ahead and save both that and the head of file.

176
00:11:04,100 --> 00:11:11,030
‫Go back into the project and exit play which I left going hit compile here and then.

177
00:11:11,810 --> 00:11:15,470
‫We should be able to dive in and have a play around.

178
00:11:15,470 --> 00:11:16,100
‫So.

179
00:11:16,190 --> 00:11:19,410
‫Up and down is working slowly, left and right.

180
00:11:20,090 --> 00:11:23,120
‫Not quite working out how I would expect.

181
00:11:23,150 --> 00:11:24,890
‫Let's check our project settings.

182
00:11:24,890 --> 00:11:25,640
‫So our look.

183
00:11:25,640 --> 00:11:26,450
‫Right.

184
00:11:26,450 --> 00:11:27,350
‫Seems okay.

185
00:11:27,740 --> 00:11:28,520
‫Thumbstick right.

186
00:11:28,520 --> 00:11:29,640
‫Thumbstick x axis.

187
00:11:29,660 --> 00:11:30,800
‫Let's check that.

188
00:11:30,800 --> 00:11:35,140
‫That's all going through into the C++ correctly bind axis look.

189
00:11:35,150 --> 00:11:36,340
‫Right, right.

190
00:11:36,350 --> 00:11:42,980
‫It's calling look right rate function or seams in order calling the your input as it should be.

191
00:11:44,710 --> 00:11:45,810
‫Dana, what happened there?

192
00:11:45,820 --> 00:11:48,550
‫I just hit recompile again and then hit play again.

193
00:11:48,550 --> 00:11:49,600
‫Sometimes you have to do this.

194
00:11:49,600 --> 00:11:55,600
‫But now the looking left and right is working up and down is working, albeit at a very, very slow

195
00:11:55,600 --> 00:11:56,350
‫pace.

196
00:11:56,350 --> 00:11:59,890
‫So we're going to tweak around with our character blueprint.

197
00:11:59,890 --> 00:12:02,440
‫Let's go and find our VP shooter character.

198
00:12:02,470 --> 00:12:03,820
‫Open up his blueprint.

199
00:12:04,500 --> 00:12:11,250
‫And then let's scroll on down and find the rotation rate, which I'm going to just multiply by ten.

200
00:12:11,400 --> 00:12:16,070
‫Try and go ten times faster, then we'll find a value that makes sense somewhere in between.

201
00:12:16,080 --> 00:12:20,490
‫This is always one way that you can try and find values is just by going and changing the order of magnitude

202
00:12:20,490 --> 00:12:21,190
‫first.

203
00:12:21,210 --> 00:12:23,990
‫Well, that's much more closely in the right ballpark.

204
00:12:24,000 --> 00:12:29,850
‫It's maybe a little too sensitive, so maybe I just slam that down by a half.

205
00:12:30,090 --> 00:12:32,250
‫Try about 50 this time.

206
00:12:32,250 --> 00:12:33,750
‫Not 500, but 50.

207
00:12:33,780 --> 00:12:35,020
‫Let's try that out.

208
00:12:35,040 --> 00:12:38,970
‫Hit play and move my stick around.

209
00:12:39,330 --> 00:12:41,190
‫That's feeling much more natural.

210
00:12:41,220 --> 00:12:44,160
‫You might want to go somewhere just a little bit in between those two.

211
00:12:44,190 --> 00:12:45,920
‫So go in between the two.

212
00:12:45,930 --> 00:12:51,750
‫Again, I'll say about 70 this time, rather than going all the way to 170 might be the right rate.

213
00:12:51,750 --> 00:12:53,730
‫Let's see if we've hit gold.

214
00:12:53,730 --> 00:12:54,810
‫Yes, I think so.

215
00:12:54,810 --> 00:12:57,290
‫I think 70 is going to be the right rate for me to move around.

216
00:12:57,300 --> 00:13:03,870
‫Obviously, this is the kind of thing that often games allow you to tweak or allow the player to tweak

217
00:13:03,870 --> 00:13:04,650
‫in the settings.

218
00:13:04,650 --> 00:13:06,210
‫We're not going to look into that.

219
00:13:06,210 --> 00:13:12,120
‫That's beyond the scope of this section, but it is something that you might potentially want to expose

220
00:13:12,120 --> 00:13:14,070
‫to users in your own games.

221
00:13:14,880 --> 00:13:15,210
‫Cool.

222
00:13:15,210 --> 00:13:19,650
‫So in that lecture we have seen the difference between controller input and mouse input and how we have

223
00:13:19,650 --> 00:13:22,770
‫to deal with rates instead of absolute movements.

224
00:13:22,950 --> 00:13:28,930
‫So in the next lecture, we're going to look at that third person camera that I kept hinting at.

225
00:13:28,950 --> 00:13:29,760
‫See you there.

