﻿1
00:00:04,370 --> 00:00:05,330
‫Hello and welcome.

2
00:00:05,330 --> 00:00:10,250
‫In this lecture, we're going to make our mover do some moving by checking a checkbox.

3
00:00:10,250 --> 00:00:14,780
‫We will enable it to move and move at a constant speed.

4
00:00:14,780 --> 00:00:19,460
‫And we're going to be doing this using some library functions this time from within.

5
00:00:19,460 --> 00:00:20,150
‫Unreal.

6
00:00:20,150 --> 00:00:24,920
‫So it'll put all of our knowledge of header files and includes to the test.

7
00:00:24,920 --> 00:00:26,780
‫Let's dive in and see how it works.

8
00:00:27,380 --> 00:00:34,670
‫So the way I want this mover to work is that I want it to move smoothly from where it started to a target

9
00:00:34,670 --> 00:00:38,540
‫offset over a period of a certain number of seconds.

10
00:00:38,540 --> 00:00:43,640
‫So the way we're going to need to configure this is to add in some new properties into the header file.

11
00:00:43,640 --> 00:00:49,010
‫So let's start off by adding a private section to the head of file and then we're going to add a new

12
00:00:49,010 --> 00:00:59,060
‫property that's going to be edit anywhere, which is going to define the offset, the move offset.

13
00:00:59,060 --> 00:01:03,650
‫So how far this mover should move when activated.

14
00:01:03,710 --> 00:01:09,560
‫So the way we're going to do that is going to use an F vector and we're going to call it the move offset

15
00:01:09,560 --> 00:01:11,960
‫like so I won't give it a default value.

16
00:01:11,990 --> 00:01:13,610
‫We'll do that in the editor.

17
00:01:13,880 --> 00:01:19,370
‫Then I'm going to create another new property which is again going to be edit anywhere, which is going

18
00:01:19,370 --> 00:01:24,050
‫to be the amount of time it takes to move to the target.

19
00:01:24,050 --> 00:01:31,790
‫So we're going to have that be a float, which is move time and I'm going to set that at a default value

20
00:01:31,790 --> 00:01:33,410
‫of, say, 4 seconds.

21
00:01:33,440 --> 00:01:39,740
‫Now, there's one more thing that I want to put in here, which is a Boolean just for now, which is

22
00:01:39,740 --> 00:01:47,060
‫going to allow us to activate the mover so that it's going to move down when we activate this boolean.

23
00:01:47,060 --> 00:01:49,790
‫So let's create another U property again.

24
00:01:49,790 --> 00:01:57,560
‫Edit anywhere so that we can edit it even while we're playing and is going to be a boolean saying should

25
00:01:57,740 --> 00:02:01,100
‫move and by default it's going to be set to false.

26
00:02:01,100 --> 00:02:07,700
‫So when we check this off in the editor, when we're playing, it's going to go and move to its target

27
00:02:07,700 --> 00:02:08,750
‫move offset.

28
00:02:08,750 --> 00:02:13,340
‫Now previously when we had a moving component, we did all the steps manually.

29
00:02:13,340 --> 00:02:17,600
‫But I want to show you that there's actually some functionality built in to do a lot of the calculations

30
00:02:17,600 --> 00:02:18,050
‫we need.

31
00:02:18,050 --> 00:02:24,830
‫It's built right into Unreal and there's a function called V interpret constant too.

32
00:02:24,830 --> 00:02:28,460
‫And what's interesting about it, let's have a look at the remarks.

33
00:02:28,460 --> 00:02:36,740
‫So interpolate a vector from a current vector to a target vector using a constant step.

34
00:02:36,740 --> 00:02:43,940
‫So that means that over time it we're going to move from current to target at a certain speed and it's

35
00:02:43,940 --> 00:02:47,330
‫going to do that constantly, which sounds like exactly what we want.

36
00:02:47,330 --> 00:02:52,430
‫We want to move from our current location to a target offset location at a constant speed.

37
00:02:52,640 --> 00:02:58,700
‫Now, you can see if you have a look at the syntax for this function, you can see that it has a return

38
00:02:58,700 --> 00:02:59,990
‫type of F vector.

39
00:02:59,990 --> 00:03:03,590
‫So that's the new location that it's interpolating.

40
00:03:03,770 --> 00:03:06,620
‫Then it has two inputs.

41
00:03:06,620 --> 00:03:14,360
‫We've got a current F vector and don't worry about the other symbols around this effect of for now we

42
00:03:14,360 --> 00:03:21,170
‫just the important thing is that it is a current vector and then the target that we want it to eventually

43
00:03:21,170 --> 00:03:21,950
‫reach.

44
00:03:22,190 --> 00:03:25,220
‫Then it has the delta time.

45
00:03:25,220 --> 00:03:32,180
‫So it uses this to make the movement frame rate independent and in the interpolation speed.

46
00:03:32,180 --> 00:03:37,220
‫So how fast should we be moving from our current location to the target?

47
00:03:37,220 --> 00:03:45,530
‫Now you will notice that up here in the documentation it actually has a section that says include and

48
00:03:45,530 --> 00:03:51,800
‫this tells you the include line you're going to need in your C++ file in order to be able to use this

49
00:03:51,800 --> 00:03:52,280
‫function.

50
00:03:52,280 --> 00:04:00,860
‫And as we've seen in the previous video, the include line allows us to copy in the definitions from

51
00:04:00,860 --> 00:04:02,390
‫this particular file.

52
00:04:02,390 --> 00:04:05,990
‫And one of the definitions is the definition for this function.

53
00:04:05,990 --> 00:04:13,250
‫So it allows us to use this V interpret constant to now the V in front of this function basically means

54
00:04:13,250 --> 00:04:15,170
‫that it does interpolation on vectors.

55
00:04:15,170 --> 00:04:20,870
‫That's why it's called V interpretation as opposed to other interpolation functions that are also available

56
00:04:20,870 --> 00:04:22,430
‫in this library file.

57
00:04:22,430 --> 00:04:24,140
‫So let's have a look at how we would use it.

58
00:04:24,140 --> 00:04:29,900
‫First of all, we're going to copy the include line from the documentation and we're going to go over

59
00:04:29,900 --> 00:04:34,580
‫into our move of CP where we want to implement this in the body of the tick component.

60
00:04:34,580 --> 00:04:38,660
‫But they include we do not include within the body of the tick component.

61
00:04:38,660 --> 00:04:41,900
‫We have to do the includes all at the top of the file.

62
00:04:42,050 --> 00:04:47,660
‫So that's where I'm going to put mine and I'm going to put mine after the include of mover H.

63
00:04:47,660 --> 00:04:53,240
‫So we're going to put in and include for math, forward slash, unreal math utility.

64
00:04:53,660 --> 00:04:59,930
‫H Now what we can do is we can actually use the function within our tick component.

65
00:04:59,930 --> 00:05:03,550
‫Let's just get rid of the code that we've already got into it.

66
00:05:03,560 --> 00:05:03,800
‫Compute.

67
00:05:04,020 --> 00:05:09,300
‫Because we were using that to understand how to call functions on other actors.

68
00:05:10,140 --> 00:05:17,190
‫And what we need to do is if you scroll up, you can see the way to call this is F Mass Colon, Colon

69
00:05:17,190 --> 00:05:18,770
‫V Intercept, constant two.

70
00:05:18,780 --> 00:05:27,630
‫So we kind of doing this colon colon operator that looks inside the F math class, which organizes together

71
00:05:27,630 --> 00:05:30,180
‫all these maths utilities.

72
00:05:30,180 --> 00:05:33,300
‫So we're going to do F math.

73
00:05:33,330 --> 00:05:34,500
‫Colon.

74
00:05:35,340 --> 00:05:41,460
‫And here you can see a bunch of autocomplete coming up for different maths functions included in that

75
00:05:41,460 --> 00:05:44,760
‫header file that we've just included into this file.

76
00:05:44,760 --> 00:05:48,900
‫So you can have a look through, see any of the interesting stuff is in here, I can see a bunch of

77
00:05:48,900 --> 00:05:56,580
‫interpolation, circular interpolations, etc. but we wanted the V interpret constant to and we can

78
00:05:56,580 --> 00:06:04,080
‫hit tab to complete that and then open some parentheses and we can see the arguments that we need to

79
00:06:04,080 --> 00:06:09,180
‫be passing in the current, the target delta time and the intercept speed.

80
00:06:09,180 --> 00:06:13,920
‫So let's start creating some variables to hold some of these.

81
00:06:14,250 --> 00:06:22,020
‫So first of all, we need an F vector which is going to be our current location and we're not going

82
00:06:22,020 --> 00:06:23,370
‫to set that for just yet.

83
00:06:23,370 --> 00:06:31,260
‫Then we're going to have an F vector for the target location, and then we're going to get a float for

84
00:06:31,260 --> 00:06:32,340
‫the speed.

85
00:06:33,090 --> 00:06:38,130
‫And we're going to have to calculate each of these individually to figure out how we can make this movement

86
00:06:38,130 --> 00:06:38,640
‫happen.

87
00:06:38,640 --> 00:06:42,450
‫So the current location is going to be relatively straightforward.

88
00:06:42,450 --> 00:06:46,440
‫We need to get the current location of the owning actor.

89
00:06:46,440 --> 00:06:47,190
‫So how do we do that?

90
00:06:47,190 --> 00:06:50,370
‫Let's replace this semicolon with an equal sign.

91
00:06:50,400 --> 00:06:54,750
‫Then we're going to do a get owner pair of parentheses.

92
00:06:54,930 --> 00:06:56,370
‫Then we're going to do an arrow.

93
00:06:56,370 --> 00:07:05,580
‫So we're going to be calling a function on the owning actor, and we're going to do get actor location

94
00:07:05,700 --> 00:07:08,520
‫and then a pair of parentheses and a semicolon to end it.

95
00:07:08,520 --> 00:07:12,570
‫So that gets us the current location of the owning actor.

96
00:07:12,750 --> 00:07:15,000
‫Now, what about our target location?

97
00:07:15,000 --> 00:07:21,000
‫Well, we know that we've got a property called the move offset, so that's going to be involved here.

98
00:07:21,000 --> 00:07:26,640
‫But we do need to add the original location to this move offset.

99
00:07:26,820 --> 00:07:32,820
‫So for that, we need to capture the original location in Biggin play.

100
00:07:32,820 --> 00:07:34,860
‫So we need a variable to store it in.

101
00:07:34,860 --> 00:07:38,820
‫So let's go over to our mover H and it's not going to be an edit anywhere.

102
00:07:38,820 --> 00:07:40,460
‫Once I'm going to put it under our U.

103
00:07:40,470 --> 00:07:46,590
‫Properties, it's going to be an F vector called Original Location.

104
00:07:47,220 --> 00:07:49,020
‫We're not going to set it to anything here.

105
00:07:49,020 --> 00:07:54,480
‫Then we're going to go over into our mover CP into begin play, remove this comment line and put our

106
00:07:54,480 --> 00:08:06,180
‫own code, which is going to be that the original location is equal to get owner parentheses arrow get

107
00:08:06,180 --> 00:08:08,790
‫actor location like so.

108
00:08:08,790 --> 00:08:13,260
‫So now that we've got our original location captured and begin play, we can use it in TTIC.

109
00:08:13,260 --> 00:08:21,360
‫So we go over into Tick and we set our target location equal to the original location plus the move

110
00:08:21,360 --> 00:08:21,870
‫offset.

111
00:08:21,870 --> 00:08:25,560
‫So that's our target location and finally our speed.

112
00:08:25,560 --> 00:08:32,040
‫Well, this is essentially the distance that we need to move divided by the time which we need to move

113
00:08:32,070 --> 00:08:32,610
‫over.

114
00:08:32,610 --> 00:08:38,820
‫So if we've got a target location and we've got an original location, we need to find the distance

115
00:08:38,820 --> 00:08:45,270
‫between these two, which we can do with an F vector, colon, colon distance.

116
00:08:45,270 --> 00:08:54,750
‫Then we pass in to the parentheses, the original location and the target location.

117
00:08:54,930 --> 00:08:58,260
‫So that gives us the distance between these two vectors.

118
00:08:58,260 --> 00:09:05,400
‫And then we are going to divide that through by what did we have over and over called the move time.

119
00:09:05,730 --> 00:09:08,970
‫So that gives us the speed at which we should be moving.

120
00:09:09,210 --> 00:09:13,920
‫And now we can use these as arguments to have V intercept constant too.

121
00:09:13,920 --> 00:09:20,730
‫So we've got first of all, we need to give it the current location and then the target location.

122
00:09:21,150 --> 00:09:27,210
‫Then we're going to tell it the Delta time, which is just already a parameter in tick component.

123
00:09:27,220 --> 00:09:31,890
‫So we just need to pass that through and then we've got the intercept speed.

124
00:09:31,890 --> 00:09:38,970
‫So we're just going to pass in the speed like so put a semicolon on the end of that line and this is

125
00:09:38,970 --> 00:09:40,410
‫essentially the new location.

126
00:09:40,410 --> 00:09:50,130
‫So let's store that into a new variable F vector called new location equal to this cool.

127
00:09:50,430 --> 00:09:54,300
‫Now we need to do something with that new location because it's no good just having calculated it,

128
00:09:54,330 --> 00:09:57,960
‫we do actually need to move the actor to the new location.

129
00:09:58,290 --> 00:09:59,370
‫So that's what we're going to do.

130
00:09:59,400 --> 00:10:02,280
‫We're going to call it on get owner.

131
00:10:02,280 --> 00:10:03,740
‫So we do a get own.

132
00:10:04,730 --> 00:10:06,640
‫Parentheses Arrow.

133
00:10:06,650 --> 00:10:15,680
‫And then we're going to do a set actor location and we're going to pass in the new location like so

134
00:10:15,680 --> 00:10:17,780
‫and have a semicolon at the end of the line.

135
00:10:17,960 --> 00:10:20,990
‫So let's go ahead and compile this and see if it works.

136
00:10:20,990 --> 00:10:25,280
‫So if we go over into the dungeon, select the wall that we want to move, you can now see that the

137
00:10:25,280 --> 00:10:32,990
‫mover component has got a move offset, which I'm going to want to do in the Z direction, and I think

138
00:10:32,990 --> 00:10:35,480
‫I'm going to do -600.

139
00:10:35,960 --> 00:10:38,930
‫And then the move time, 4 seconds should be just fine.

140
00:10:38,930 --> 00:10:44,060
‫So let's save that and then hit play and see if it moves so it's not moving.

141
00:10:44,060 --> 00:10:50,030
‫And there's an error in the output log saying that the mobility of the actor has been set to static,

142
00:10:50,030 --> 00:10:51,350
‫which is why it can't move.

143
00:10:51,350 --> 00:10:59,780
‫So if we select the actor again and we look at its mobility settings, you can see in fact the mobility

144
00:10:59,780 --> 00:11:01,370
‫settings of the static mesh component.

145
00:11:01,370 --> 00:11:03,920
‫So select the static mesh component, then look at the mobility.

146
00:11:03,920 --> 00:11:06,740
‫You can see it's set to static, which basically means it's not allowed to move.

147
00:11:06,890 --> 00:11:11,900
‫Let's switch that over to movable because we do want it to move and then let's go ahead and hit play.

148
00:11:11,930 --> 00:11:18,200
‫Now you can see in the darkness that the wall was going down, which is perfect.

149
00:11:18,200 --> 00:11:23,180
‫I do think we've got a mover somewhere else in our scene up on this pillar here that it's also trying

150
00:11:23,180 --> 00:11:23,540
‫to move.

151
00:11:23,540 --> 00:11:24,680
‫So let's not do that.

152
00:11:24,680 --> 00:11:31,520
‫Let's delete the mover component that we added in there just for testing and it should give us no errors

153
00:11:31,520 --> 00:11:32,510
‫in the output log.

154
00:11:32,510 --> 00:11:38,450
‫If we go ahead and hit play now, we should just have that wall going down to its target location.

155
00:11:38,450 --> 00:11:42,890
‫So let's challenge you to make it move with the boolean that we created that you property.

156
00:11:42,890 --> 00:11:48,770
‫So you're going to wrap the code in an appropriate if statement and the appropriate code so that it

157
00:11:48,770 --> 00:11:52,730
‫only moves the platform when that Boolean is true.

158
00:11:53,000 --> 00:11:58,520
‫And then you're going to recompile the code and play and eject using F8 and then change the boolean

159
00:11:58,520 --> 00:12:02,420
‫and observe the see whether it moves when you check that boolean.

160
00:12:02,420 --> 00:12:04,400
‫So pause the video and have a go.

161
00:12:07,410 --> 00:12:07,740
‫Okay.

162
00:12:07,770 --> 00:12:08,510
‫Welcome back.

163
00:12:08,520 --> 00:12:14,820
‫So let's go and wrap this tick component stuff in an if statement, not super, but everything else

164
00:12:14,820 --> 00:12:15,390
‫we're going to do.

165
00:12:15,390 --> 00:12:24,450
‫If should move, then open some parentheses and move all this code in remembering to indent it one level

166
00:12:24,450 --> 00:12:29,220
‫because we're inside parentheses and we want to show that this would only be executed within the if

167
00:12:29,220 --> 00:12:29,610
‫statement.

168
00:12:29,610 --> 00:12:37,230
‫Make it easy for us to read control all f 11 to compile and then we should be able to go and hit play

169
00:12:37,230 --> 00:12:42,300
‫and hit F eight to eject if we have got our mouse captured.

170
00:12:42,660 --> 00:12:49,680
‫And then we're going to go in to have a look at our outlier, we're going to try and find the wall or

171
00:12:49,680 --> 00:12:56,340
‫we can just click in the scene and then we're going to select our move a component and check should

172
00:12:56,340 --> 00:13:00,540
‫move and they go, the wall starts to move when that happens.

173
00:13:00,570 --> 00:13:01,350
‫Great stuff.

174
00:13:01,350 --> 00:13:03,570
‫I will see you in the next lecture.

