﻿1
00:00:04,260 --> 00:00:05,280
‫Hello and welcome.

2
00:00:05,280 --> 00:00:11,520
‫In this lecture, we're going to be getting some line tracing set up so that we can shoot at the walls

3
00:00:11,520 --> 00:00:14,250
‫and see these debug points appearing.

4
00:00:14,250 --> 00:00:18,510
‫And we're going to be doing this using a new function line trace by channel, and we're going to see

5
00:00:18,510 --> 00:00:22,470
‫why we're using that over line trace by object type, which is what we've used before.

6
00:00:22,500 --> 00:00:24,330
‫Let's dive in and see how it's done.

7
00:00:25,430 --> 00:00:31,220
‫So back in our building escape, we used line traces and we use this function here, the line trace

8
00:00:31,610 --> 00:00:32,870
‫by object type.

9
00:00:32,870 --> 00:00:36,350
‫And is this what we want to be using?

10
00:00:36,440 --> 00:00:42,200
‫Well, what is the difference between line trace by object type and its very close sibling, which is

11
00:00:42,200 --> 00:00:44,450
‫a line trace by channel.

12
00:00:45,170 --> 00:00:53,090
‫Well, object type says, I want to search through this line and see if I find an object that matches

13
00:00:53,090 --> 00:00:53,540
‫this type.

14
00:00:53,540 --> 00:01:01,700
‫So in I believe what we used in building escape was something like the physics body object type and

15
00:01:01,700 --> 00:01:04,250
‫that's great, it'll hit physics bodies.

16
00:01:04,250 --> 00:01:10,010
‫But if you decide suddenly that you want something else to be hit a ball, it doesn't leave much room

17
00:01:10,010 --> 00:01:10,580
‫for options.

18
00:01:10,580 --> 00:01:16,490
‫So channel is better for that because it allows us to define our own custom channels and then define

19
00:01:16,490 --> 00:01:22,100
‫what sorts of objects are transparent to that channel and which ones block it.

20
00:01:22,100 --> 00:01:29,420
‫So that's great because what we want to be able to do is say, okay, maybe a Bush type of thing is

21
00:01:30,070 --> 00:01:36,650
‫can't block a bullet, whereas a wall will block a bullet, but it won't be taking any damage but that

22
00:01:36,650 --> 00:01:38,000
‫we can deal with later on.

23
00:01:38,180 --> 00:01:45,200
‫So channels are the route we're going to go down and we can find the correct method here by doing control.

24
00:01:45,200 --> 00:01:50,990
‫P And by the way, there's this little extra cool bit that I only recently just learnt is if you use

25
00:01:50,990 --> 00:01:58,610
‫the ACT symbol, you can search for symbols within this file and or even other files, but if you have

26
00:01:58,610 --> 00:02:00,170
‫the file open it's much quicker.

27
00:02:00,350 --> 00:02:07,190
‫Then you could do something like line trace and you can see there's giving us the list of all the symbols

28
00:02:07,190 --> 00:02:14,210
‫which are functions or classes or variables, and we can find that line, trace, test line, trace,

29
00:02:14,210 --> 00:02:15,920
‫single by channel by object type.

30
00:02:15,920 --> 00:02:21,410
‫We want this first one line trace, single BI channel, which is going to have an out parameter for

31
00:02:21,410 --> 00:02:22,340
‫what we hit.

32
00:02:22,430 --> 00:02:27,800
‫The starting point, the ending point, the collision trace channel will come to that in just a little

33
00:02:27,800 --> 00:02:33,290
‫bit and then some query parameters which have got some defaults so we actually don't have to worry about.

34
00:02:33,290 --> 00:02:38,870
‫So just those first few things, the Outhit Start, end and Trace Channel are what we want to worry

35
00:02:38,870 --> 00:02:39,350
‫about.

36
00:02:39,680 --> 00:02:41,750
‫Let's set up a Trace channel.

37
00:02:41,750 --> 00:02:45,320
‫We're going to go to settings and project settings for this.

38
00:02:45,320 --> 00:02:48,950
‫And then we're looking under engine for the collisions area.

39
00:02:48,950 --> 00:02:53,300
‫And under here you can see we've got object channels and trace channels.

40
00:02:53,300 --> 00:02:57,590
‫Object channels is actually just another way of saying different types of objects.

41
00:02:57,590 --> 00:03:02,120
‫So if you wanted to have as well as the default sets of objects like pawns and stuff like that, if

42
00:03:02,120 --> 00:03:06,140
‫you wanted a new category of object, you could go down the object channel route.

43
00:03:06,140 --> 00:03:13,430
‫But the traces allow you to define the opposite end of the spectrum, which is like, I've got a bullet,

44
00:03:13,460 --> 00:03:15,740
‫what objects can it hit?

45
00:03:15,740 --> 00:03:21,860
‫So we're going to go down this route, add a new trace channel, and we're going to call this bullet.

46
00:03:22,600 --> 00:03:25,840
‫And the default response is going to be.

47
00:03:25,840 --> 00:03:29,290
‫BLOCK Which basically means that all object types are going to.

48
00:03:29,290 --> 00:03:36,100
‫BLOCK Unless we now specify otherwise, we can go ahead and accept this and we can look at our presets

49
00:03:36,100 --> 00:03:36,820
‫down here.

50
00:03:37,270 --> 00:03:42,490
‫If we just expand that out, the presets are going to show you that we have a bunch of different things

51
00:03:42,490 --> 00:03:48,100
‫that we can apply to, things we can say, we want this to be a physics actor, in which case it's object

52
00:03:48,100 --> 00:03:52,840
‫type, which is going to be what is a predefined object channel will be physics body.

53
00:03:52,840 --> 00:04:00,550
‫But if we expand this out, you can see what its reaction is to the different types of traces here.

54
00:04:00,550 --> 00:04:06,280
‫So we've got our trace types camera, our own bullet visibility, it blocks all of these and then it's

55
00:04:06,280 --> 00:04:07,030
‫got object types.

56
00:04:07,030 --> 00:04:13,660
‫So that's how it interacts physics wise with other objects such as pawns and vehicles, etc. That's

57
00:04:13,660 --> 00:04:16,750
‫not how it interacts with line trace by object.

58
00:04:16,750 --> 00:04:19,390
‫That's slightly confusing and it's confused me before.

59
00:04:19,690 --> 00:04:26,950
‫So the trace type is what's interesting and we can just go and have a look through here and see no collision

60
00:04:26,950 --> 00:04:28,990
‫should be set up to not collide.

61
00:04:28,990 --> 00:04:31,900
‫So let's make our bullets not collide with that as well.

62
00:04:31,900 --> 00:04:39,160
‫So just overriding some of the presets such that our bullet works as we would expect, overlap all,

63
00:04:39,160 --> 00:04:42,640
‫for example, should basically overlap with the bullet.

64
00:04:42,640 --> 00:04:49,870
‫And probably invisible wall and invisible wall dynamic should also be ignored for the purposes of our

65
00:04:49,870 --> 00:04:50,710
‫bullet.

66
00:04:50,770 --> 00:04:51,940
‫Same with dynamic here.

67
00:04:51,940 --> 00:04:55,300
‫You can see that we're basically ending up with something that's quite similar to a visibility trace.

68
00:04:55,300 --> 00:05:00,850
‫But the reason for keeping it separate is that we might want to make slight distinctions, such as you

69
00:05:00,850 --> 00:05:04,660
‫can see, you can't see through this bush, but you can shoot through it.

70
00:05:04,660 --> 00:05:09,100
‫Those kinds of things mean that having our own trace channel is really, really handy.

71
00:05:09,100 --> 00:05:14,800
‫Now we'd like to be able to use this trace channel in code, and it's a bit funky how we have to do

72
00:05:14,800 --> 00:05:21,490
‫this because there's an enum here, an E collision channel, and if we go F12 to its definition, you

73
00:05:21,490 --> 00:05:27,580
‫can see there's a bunch for the predefined ones, world static -- visibility, etc. down here, but

74
00:05:27,580 --> 00:05:33,640
‫then there's a bunch more engine trace channel one, two and Game Trace Channel one, two, three,

75
00:05:33,640 --> 00:05:35,050
‫etc. predefined.

76
00:05:35,500 --> 00:05:37,570
‫Which one of ours is this?

77
00:05:37,570 --> 00:05:39,970
‫You know, we don't have a bullet in here.

78
00:05:40,300 --> 00:05:42,760
‫We actually have to use one of these game trace channels one.

79
00:05:42,760 --> 00:05:44,620
‫So it's really a little bit confusing.

80
00:05:44,620 --> 00:05:45,790
‫Which one is it?

81
00:05:45,880 --> 00:05:50,980
‫So the way you do this is by going to your project folder and go into config.

82
00:05:51,130 --> 00:05:56,170
‫And what we want is the default engine INI and we want to open that in a text editor.

83
00:05:56,170 --> 00:05:58,300
‫So you can do that in any text that you like.

84
00:05:58,330 --> 00:06:03,310
‫I like to drag it into Visual Studio code, so that Visual Studio code is the one opening it.

85
00:06:03,850 --> 00:06:10,960
‫And in here we want to essentially look for our bullet and see what it has been assigned to.

86
00:06:10,960 --> 00:06:17,020
‫And I think this first line here tells us that the channel it's been given is the game Trace Channel

87
00:06:17,020 --> 00:06:17,680
‫one.

88
00:06:17,710 --> 00:06:18,430
‫Fantastic.

89
00:06:18,430 --> 00:06:21,940
‫So that's what we are going to use when we're doing our line trace.

90
00:06:22,180 --> 00:06:27,130
‫So let's start to get the structure of this line trace in place.

91
00:06:27,900 --> 00:06:30,540
‫The first thing we're going to need is a start point.

92
00:06:30,540 --> 00:06:31,290
‫We already have that.

93
00:06:31,290 --> 00:06:33,050
‫That's the location of our viewport.

94
00:06:33,060 --> 00:06:37,890
‫We're also going to need an endpoint for our line trace that's slightly harder to calculate.

95
00:06:38,010 --> 00:06:45,930
‫So let's create an F vector for our end, and we're going to calculate this by using our stop point,

96
00:06:46,380 --> 00:06:53,220
‫plus the rotation multiplied by the amount, the distance that we want to go away.

97
00:06:53,400 --> 00:06:58,170
‫Not the rotation, but a vector that points in the direction of the rotation feel slightly confusing,

98
00:06:58,170 --> 00:07:05,220
‫but actually if you do rotation vector, this gives you a vector that points in the direction of this

99
00:07:05,220 --> 00:07:05,880
‫rotation.

100
00:07:05,880 --> 00:07:11,220
‫It's kind of doing the opposite of what we were doing in the animation blueprint to get a rotation from

101
00:07:11,220 --> 00:07:11,810
‫a vector.

102
00:07:11,820 --> 00:07:13,140
‫This goes the other way.

103
00:07:13,200 --> 00:07:20,880
‫So we're going to do location plus this rotation vector, and then we want essentially a max range.

104
00:07:20,880 --> 00:07:26,010
‫So I'm going to introduce a new property here, make it edit anywhere and it's going to be a float called

105
00:07:26,010 --> 00:07:28,050
‫Max Range like so.

106
00:07:28,050 --> 00:07:33,990
‫And we can set it to a default of something like 10,000 or a thousand max range.

107
00:07:33,990 --> 00:07:37,050
‫That's going to be about 100 meters, sorry, about ten meters.

108
00:07:37,140 --> 00:07:42,870
‫And we're going to go over to the rotation vector multiplied by the max range.

109
00:07:42,870 --> 00:07:46,740
‫So that's going to be the vector that we get from that rotation is going to be a size one.

110
00:07:46,740 --> 00:07:51,030
‫Multiplying it by the max range will make it a vector of size, whatever the max range is.

111
00:07:51,030 --> 00:07:54,780
‫And then we add that on top of the location to get us the end point.

112
00:07:54,810 --> 00:07:57,810
‫Don't worry if you don't follow that math's 100%.

113
00:07:58,110 --> 00:08:01,530
‫The important thing is that this is how we want to get to our endpoint.

114
00:08:01,530 --> 00:08:06,510
‫Then I'm just going to put a to do line in here to add in some line tracing and we're going to remove

115
00:08:06,510 --> 00:08:12,990
‫this draw debug camera because I want to do a different draw debug helper here.

116
00:08:13,020 --> 00:08:16,950
‫I want to draw a debug point which you can find here.

117
00:08:16,950 --> 00:08:20,610
‫It takes in the world, takes in a position and a size and a color.

118
00:08:20,610 --> 00:08:24,660
‫And whether it's persistent or not, we probably do want it to be persistent, to be visible.

119
00:08:24,660 --> 00:08:27,600
‫So we should be able to do something along these lines.

120
00:08:27,600 --> 00:08:35,430
‫Let's see, draw debug point and we're going to do a get world right off the bat here and then we'll

121
00:08:35,430 --> 00:08:41,190
‫start off with the location of our viewport instead, just as a test to see how this draw debug point

122
00:08:41,190 --> 00:08:48,450
‫works, give it size to give it an f color of red and make its persistence true.

123
00:08:48,450 --> 00:08:53,310
‫And then we are going to capital for the semicolon and see whether this is working as hit compile over

124
00:08:53,310 --> 00:08:55,410
‫in the engine and let's hit play.

125
00:08:55,800 --> 00:08:59,640
‫So now if I shoot and move slightly back, you can see there's a point there.

126
00:08:59,640 --> 00:09:02,400
‫However, it's really, really tiny and hard to see.

127
00:09:02,400 --> 00:09:07,050
‫So they're going to increase this to 20 instead.

128
00:09:07,140 --> 00:09:08,190
‫Let's see if that's better.

129
00:09:08,190 --> 00:09:09,510
‫Compile and play.

130
00:09:09,540 --> 00:09:09,780
‫Yep.

131
00:09:09,780 --> 00:09:13,020
‫Sure enough, now I can see a very, very clear point.

132
00:09:13,260 --> 00:09:16,860
‫So it's time for your challenge to do a line trace by channel.

133
00:09:16,860 --> 00:09:22,650
‫We've done it with object types before, so hopefully we can extrapolate that to doing it by channel.

134
00:09:22,650 --> 00:09:28,290
‫So use the location and end that we have defined already as the start and end.

135
00:09:28,530 --> 00:09:31,650
‫Check the success of the result making an if statement.

136
00:09:31,650 --> 00:09:38,640
‫So only getting the out parameter or getting the parameter of the hit result and only drawing a debug

137
00:09:38,640 --> 00:09:38,940
‫point.

138
00:09:38,940 --> 00:09:45,000
‫If we successfully hit the point and remember that we're using that channel that we found in the dot

139
00:09:45,000 --> 00:09:46,080
‫INI file as well.

140
00:09:46,080 --> 00:09:51,060
‫So pause the video and see if you can sort out all of those parameters and arguments into the line trace

141
00:09:51,060 --> 00:09:56,160
‫and get that debug point drawing where we hit with our line trace.

142
00:09:56,730 --> 00:10:02,400
‫Now at this stage we aren't doing anything smart, like ignoring the player actor.

143
00:10:02,400 --> 00:10:08,160
‫So your line trace may end up hitting the player and that's okay for this challenge.

144
00:10:08,190 --> 00:10:08,700
‫Pause video.

145
00:10:08,700 --> 00:10:09,270
‫Have a go.

146
00:10:10,700 --> 00:10:11,030
‫Okay.

147
00:10:11,030 --> 00:10:11,690
‫Welcome back.

148
00:10:11,720 --> 00:10:13,910
‫So let's dive right in.

149
00:10:13,910 --> 00:10:18,410
‫We're going to get the world, first of all, and do an arrow to that.

150
00:10:18,410 --> 00:10:23,210
‫We're going to go to do a line trace single by channel.

151
00:10:24,170 --> 00:10:25,910
‫Then we're going to need a hit result.

152
00:10:25,910 --> 00:10:32,870
‫So our parameter, we need to first declare our hit result struct to pass in as an out parameter.

153
00:10:33,110 --> 00:10:37,820
‫It's going to call it hit and are going to pass it in as the first argument here.

154
00:10:37,850 --> 00:10:39,650
‫Then we need the location.

155
00:10:40,410 --> 00:10:42,000
‫And we need the end.

156
00:10:42,090 --> 00:10:43,490
‫And then what?

157
00:10:43,500 --> 00:10:44,430
‫What comes up next?

158
00:10:44,430 --> 00:10:47,470
‫The E collision e collision channel.

159
00:10:47,490 --> 00:10:49,530
‫So that's going to be an E collision channel.

160
00:10:49,530 --> 00:10:50,490
‫Colon.

161
00:10:50,490 --> 00:10:53,610
‫And then it should be e c, what did we say?

162
00:10:53,610 --> 00:10:55,440
‫Let's go and have a look in the default engine.

163
00:10:55,440 --> 00:11:01,400
‫Any e cc game trace channel one is the one that the default any has configured it as.

164
00:11:01,410 --> 00:11:03,360
‫Are there any more arguments here that we need?

165
00:11:03,360 --> 00:11:04,770
‫Let's go along.

166
00:11:04,800 --> 00:11:06,750
‫We've got the collision parameters which are defaulted out.

167
00:11:06,750 --> 00:11:10,050
‫So no, we do not need anything in here.

168
00:11:10,230 --> 00:11:14,160
‫And then what we can do is we need a boolean result for this.

169
00:11:14,160 --> 00:11:16,110
‫So B success.

170
00:11:16,910 --> 00:11:19,020
‫And it sounds very helpful.

171
00:11:19,020 --> 00:11:20,450
‫Doesn't it be success?

172
00:11:20,810 --> 00:11:23,360
‫Let's say an if be success.

173
00:11:24,230 --> 00:11:26,720
‫We're going to want to draw that debug point.

174
00:11:26,720 --> 00:11:27,950
‫So we're going to move this down.

175
00:11:27,950 --> 00:11:35,300
‫I can do this with Alt and then the arrow moves a line around like this and then I can indent it with

176
00:11:35,300 --> 00:11:41,390
‫a control and the right square bracket on your keyboard and that gets it to look like so.

177
00:11:41,390 --> 00:11:46,550
‫And now instead of the location, which is the start point, we actually want the hit location.

178
00:11:46,550 --> 00:11:50,270
‫So that's going to be hit dot location like so.

179
00:11:50,270 --> 00:11:54,650
‫And it looks like I'm missing a semicolon on the end of this line here.

180
00:11:54,650 --> 00:11:56,750
‫Let's build that and give it a go.

181
00:11:57,020 --> 00:12:02,750
‫Once that's compiled, let's hit play, go into the world and try and shoot at our walls.

182
00:12:02,960 --> 00:12:03,650
‫There you go.

183
00:12:03,650 --> 00:12:07,490
‫You can see we've got a point showing up on the wall just where I shot.

184
00:12:07,490 --> 00:12:09,020
‫I can do this multiple times.

185
00:12:09,140 --> 00:12:16,070
‫It seems to hit if I go to far from a wall, it doesn't hit at all because of our max range being quite

186
00:12:16,070 --> 00:12:16,730
‫short.

187
00:12:16,730 --> 00:12:21,230
‫And you can see once I get within the max range, it does hit and it does draw a point.

188
00:12:21,230 --> 00:12:23,930
‫So that is a challenge successfully completed.

189
00:12:23,930 --> 00:12:29,270
‫We're now able to show and line trace to a particular point.

190
00:12:29,270 --> 00:12:35,510
‫The next step is going to be getting that to actually show some particle effects, which will be much

191
00:12:35,510 --> 00:12:38,630
‫cooler than just drawing a debug point for that.

192
00:12:38,630 --> 00:12:40,160
‫I'll see you in the next lecture.

