﻿1
00:00:04,350 --> 00:00:05,340
‫Hello and welcome.

2
00:00:05,340 --> 00:00:11,490
‫In this lecture, we're going to be setting up our first geometry trace so that when we go and look

3
00:00:11,490 --> 00:00:17,970
‫at our gargoyle and we get close enough within range, then sure enough it prints out the name of the

4
00:00:17,970 --> 00:00:21,030
‫actor that has been hit by the trace.

5
00:00:21,030 --> 00:00:27,540
‫Let's dive in and see how we can do this so we're finally ready to tackle this sweep single by channel.

6
00:00:27,540 --> 00:00:31,290
‫There was a lot of pieces that we had to have in place to make it work.

7
00:00:31,290 --> 00:00:32,550
‫But finally, we're here.

8
00:00:32,700 --> 00:00:36,240
‫So let's have a look at the syntax of this function.

9
00:00:36,240 --> 00:00:43,230
‫So we are in a much better place to understand what was going on here when in these types.

10
00:00:43,230 --> 00:00:50,790
‫So the return value is a boolean, which basically tells us whether or not we found anything with the

11
00:00:50,790 --> 00:00:51,510
‫sweep.

12
00:00:51,990 --> 00:00:56,430
‫Now the second argument, as you can see here, it's a reference.

13
00:00:56,430 --> 00:00:58,050
‫It's got this ampersand.

14
00:00:58,170 --> 00:01:02,520
‫And it doesn't matter whether there's a space after the ampersand or a space between the variable name,

15
00:01:02,520 --> 00:01:07,830
‫it's all the same as long as there's an ampersand after the type saying that that type is a reference

16
00:01:07,950 --> 00:01:12,690
‫and it's a type called an F hit result, you can see that it's a struct.

17
00:01:12,810 --> 00:01:15,870
‫So this F hit result is the out hit.

18
00:01:15,870 --> 00:01:18,630
‫That is the result that comes out of the sweep.

19
00:01:18,630 --> 00:01:24,120
‫We can see what things have been hit and there's it's a struct because there's multiple different things,

20
00:01:24,120 --> 00:01:26,790
‫pieces of information that can come out of this sweep.

21
00:01:26,790 --> 00:01:31,080
‫Then we have a constant f vector reference.

22
00:01:31,080 --> 00:01:36,510
‫So this is taking our start vector by reference instead of copying it.

23
00:01:36,510 --> 00:01:40,530
‫Same with the end vector, then we've got a rotation.

24
00:01:40,530 --> 00:01:46,710
‫So this is the rotation of the shape using an f quat, which is an alternative structure to using the

25
00:01:46,710 --> 00:01:47,610
‫f rotator.

26
00:01:47,610 --> 00:01:51,690
‫We'll see how we can basically just get put in a zero rotation here because we're using a sphere.

27
00:01:51,690 --> 00:01:52,770
‫It doesn't really matter.

28
00:01:53,220 --> 00:01:59,940
‫The next thing that comes in is the Trace Channel and we'll see how to figure out what our Trace channel

29
00:01:59,940 --> 00:02:02,220
‫is called in C++.

30
00:02:02,370 --> 00:02:08,820
‫And then we've got our collision shape, which will be the last argument we need to provide, and we'll

31
00:02:08,820 --> 00:02:13,830
‫see how we can create a sphere of a certain radius by doing that.

32
00:02:13,830 --> 00:02:18,540
‫But before we begin, we'll need to know what that radius is and how have it configured.

33
00:02:18,540 --> 00:02:23,700
‫So we're going to go over into our grab a dot h, we're going to remove these functions we've been using

34
00:02:23,700 --> 00:02:27,870
‫as examples for reference references and out parameters.

35
00:02:27,870 --> 00:02:35,040
‫And we're going to create a new property which is going to be edit anywhere and it's going to be a float

36
00:02:35,310 --> 00:02:42,690
‫called the grab radius and we're going to set that to 101 metre.

37
00:02:42,690 --> 00:02:49,140
‫So let's go over into the C++ now and remove the references to print damage and has damage and we can

38
00:02:49,140 --> 00:02:53,490
‫remove any of that from the tick component as well.

39
00:02:53,490 --> 00:02:58,830
‫The whole if statement and where we're passing in the damage because here we're drawing our debug line

40
00:02:58,830 --> 00:03:03,900
‫and now we want to make a call to our sweep single by channel.

41
00:03:03,990 --> 00:03:06,150
‫So we're going to type sweep.

42
00:03:06,150 --> 00:03:13,350
‫So we're going to type get world parentheses because we know that this is a function on the new world

43
00:03:13,350 --> 00:03:14,070
‫object.

44
00:03:14,370 --> 00:03:19,500
‫Then we can do an arrow because we know that get world returns a pointer and then we're going to do

45
00:03:19,500 --> 00:03:29,040
‫a sweep single by channel like so and we're going to have to input an out parameter for it to populate

46
00:03:29,040 --> 00:03:31,710
‫as the first argument here.

47
00:03:31,800 --> 00:03:37,200
‫So we're going to create a variable that's going to be empty, that will be populated, and it's got

48
00:03:37,200 --> 00:03:38,100
‫to have the right type.

49
00:03:38,100 --> 00:03:44,640
‫So it's going to be an if f hit result and we're just going to call the variable itself hit result,

50
00:03:44,640 --> 00:03:49,500
‫put a semicolon at the end because we're not initializing it, we're not giving it any value, but we're

51
00:03:49,500 --> 00:03:55,050
‫going to pass it in for it to be given a value by the sweep single by channel function.

52
00:03:55,770 --> 00:03:57,270
‫So that's our hit result.

53
00:03:57,270 --> 00:04:04,050
‫Then we need to pass in the start and end vectors which we know are going to be not copied but taken

54
00:04:04,050 --> 00:04:05,190
‫a reference to.

55
00:04:05,430 --> 00:04:13,080
‫Now we need to populate the rotation which we can do with a simple f quote colon, colon identity,

56
00:04:13,080 --> 00:04:17,370
‫which tells us basically that this is a no rotation.

57
00:04:17,370 --> 00:04:19,290
‫That's just a bit of a weird language for it.

58
00:04:19,290 --> 00:04:23,190
‫It's a mathematical speak for meaning that this is no rotation.

59
00:04:23,760 --> 00:04:27,030
‫Next up, we need the trace collision channel.

60
00:04:27,030 --> 00:04:31,020
‫Now, how do we go about finding that trace collision channel?

61
00:04:31,170 --> 00:04:38,370
‫Well, if we go over to the folder that holds our project and we go in to config and then we go to the

62
00:04:38,370 --> 00:04:44,160
‫default engine INI right, click that and go open with Visual Studio code.

63
00:04:44,160 --> 00:04:47,700
‫And in here I'd like to search for Grabber.

64
00:04:48,030 --> 00:04:52,770
‫So you'll be able to see the collision response channel for the grabber.

65
00:04:52,770 --> 00:04:56,040
‫And it's basically been set up here in the default engine INI.

66
00:04:56,040 --> 00:05:00,990
‫It's only mentioned once in the whole file and you can see the channel name.

67
00:05:00,990 --> 00:05:02,820
‫This is the channel name in C++.

68
00:05:02,820 --> 00:05:03,750
‫It's not very.

69
00:05:04,050 --> 00:05:06,060
‫Yes, but it's s.e.c.

70
00:05:06,090 --> 00:05:13,890
‫Game Trace Channel two, so we can go ahead and copy that, and then we can go back to our grab a CP

71
00:05:13,890 --> 00:05:17,980
‫and paste it in here as the trace channel that we want.

72
00:05:18,000 --> 00:05:22,590
‫Now, this line is getting rather long, and what we can do to compensate for that is we can actually

73
00:05:22,590 --> 00:05:27,030
‫put each of these parameters on separate lines, or at least spread them out.

74
00:05:27,030 --> 00:05:29,220
‫So maybe the start and end are on the same.

75
00:05:29,220 --> 00:05:35,250
‫The identity criterion is on one line, the trace channel is on another line like so.

76
00:05:35,250 --> 00:05:39,640
‫And that just gives us a little bit more space for reading these long argument lists.

77
00:05:39,660 --> 00:05:44,130
‫Now, if we head back to the documentation, we can see that the next thing we need to pass in here

78
00:05:44,130 --> 00:05:47,250
‫is an F collision shape.

79
00:05:47,250 --> 00:05:49,890
‫So we need to construct a shape.

80
00:05:49,890 --> 00:05:52,980
‫Maybe we'll do this as a separate variable up at the top.

81
00:05:52,980 --> 00:05:57,510
‫I'll just do it before the F hit result to make it super clear that the F hit result is actually an

82
00:05:57,510 --> 00:05:58,140
‫out parameter.

83
00:05:58,140 --> 00:06:02,490
‫I'm always going to leave that as the last thing before the call to the function.

84
00:06:02,850 --> 00:06:08,970
‫So we're going to create an F collision shape, which we're going to call the sphere, and we're going

85
00:06:08,970 --> 00:06:15,210
‫to set it equal to F collision shape, colon, colon, make sphere.

86
00:06:15,210 --> 00:06:18,540
‫So that's going to create us a new sphere, collision shape.

87
00:06:18,540 --> 00:06:26,580
‫And the argument to this function is the sphere radius which we have got as the grab radius variable

88
00:06:26,580 --> 00:06:33,060
‫that we've configured as a U property but a semicolon on the end of this line and we can pass in the

89
00:06:33,060 --> 00:06:41,130
‫sphere as our final argument to the sweep channel function and put a semicolon at the end of that line.

90
00:06:41,130 --> 00:06:47,790
‫Now one more thing is that this function we know returns a boolean, which is whether we've hit anything.

91
00:06:47,790 --> 00:06:55,050
‫So I'm going to put the result into a boolean variable called has hit and that's what we're going to

92
00:06:55,050 --> 00:06:57,480
‫be using later on in this function.

93
00:06:57,480 --> 00:07:02,280
‫So I'd like to challenge you to print the hit actor's name.

94
00:07:02,280 --> 00:07:04,440
‫So now we've got this sweep happening.

95
00:07:04,440 --> 00:07:07,230
‫We should be able to get some results out of it.

96
00:07:07,230 --> 00:07:11,700
‫So use an if statement to print if we have anything at all.

97
00:07:11,700 --> 00:07:16,830
‫So if that boolean is true, that's when we're going to print out the actor name.

98
00:07:16,830 --> 00:07:22,950
‫You're going to get the actor that the Sphere Trace is hit by using the hit result struct.

99
00:07:22,950 --> 00:07:28,530
‫It's got a method on it which you can access with a dot operator because it's a struct in.

100
00:07:28,530 --> 00:07:30,300
‫It's not a pointer to the struct.

101
00:07:30,600 --> 00:07:36,630
‫You can do a dot, get actor and use the parentheses and that returns you an actor pointer.

102
00:07:37,140 --> 00:07:42,240
‫Then using that active pointer, you can get the actor's name using the get actor name or label method

103
00:07:42,240 --> 00:07:49,020
‫and think about whether you want to use the dot or arrow operator for this and then compile and test

104
00:07:49,020 --> 00:07:53,700
‫having printed out that actor name and see what you can hit in the scene.

105
00:07:53,700 --> 00:07:55,500
‫Pause the video and have a go.

106
00:07:58,460 --> 00:07:58,750
‫Okay.

107
00:07:58,750 --> 00:07:59,710
‫Welcome back.

108
00:07:59,740 --> 00:08:02,410
‫So we're going to start off with creating that if statement.

109
00:08:02,410 --> 00:08:09,100
‫So if has hit, then we're going to put some braces and we're going to do first of all, we want to

110
00:08:09,100 --> 00:08:10,270
‫get hold of that actor point.

111
00:08:10,270 --> 00:08:17,710
‫So a actor star hit actor is equal to the hit result.

112
00:08:18,670 --> 00:08:20,260
‫Dot get.

113
00:08:20,560 --> 00:08:21,420
‫Actor.

114
00:08:21,910 --> 00:08:22,690
‫Parentheses.

115
00:08:22,690 --> 00:08:22,900
‫Like.

116
00:08:22,900 --> 00:08:34,030
‫So then we're going to do a u log and we're going to write hit actor colon percent sx and we can do

117
00:08:34,060 --> 00:08:43,750
‫hit actor and because it's a pointer here, we can do hit actor arrow, get actor name or label, then

118
00:08:43,750 --> 00:08:44,860
‫some parentheses.

119
00:08:44,860 --> 00:08:51,790
‫And because this is a string, we have to put a star at the front of the whole shebang so that it can

120
00:08:52,240 --> 00:08:55,210
‫properly display it in our Yui log.

121
00:08:55,240 --> 00:08:58,660
‫Okay, so we now need to just go ahead and compile this.

122
00:08:58,660 --> 00:09:04,150
‫Then once we're in the scene, let's open up the output log and dock it to the layout so we can see

123
00:09:04,150 --> 00:09:06,640
‫it while we play and hit the play button.

124
00:09:07,390 --> 00:09:11,050
‫And instantly you can see that we are hitting that gargoyle statue.

125
00:09:11,080 --> 00:09:16,360
‫If I turn around and look at something else you can see, well, it's not very clear whether I'm not

126
00:09:16,360 --> 00:09:19,150
‫hitting anything or whether it's displaying nothing.

127
00:09:19,150 --> 00:09:24,970
‫So what I'm going to do is I'm going to put in an else to our if statement here, put some more brackets

128
00:09:24,970 --> 00:09:27,640
‫and I'm going to do another U log.

129
00:09:27,640 --> 00:09:34,450
‫And this time the text is going to say, no actor hit, let's recompile and go and play in the editor.

130
00:09:34,450 --> 00:09:35,230
‫And you can see it now.

131
00:09:35,230 --> 00:09:41,230
‫It's saying no actor hit all the time until I go and start looking at the gargoyle.

132
00:09:41,230 --> 00:09:43,900
‫And now it's saying that the gargoyle is the thing being hit.

133
00:09:43,900 --> 00:09:49,540
‫If I move too far back out of there for me to range, you can see I see that it's saying no actor being

134
00:09:49,540 --> 00:09:50,740
‫hit again.

135
00:09:50,770 --> 00:09:51,280
‫Great stuff.

136
00:09:51,280 --> 00:09:58,090
‫So we have now done a geometry sweep with a spherical object and we can see that it is indeed reacting

137
00:09:58,270 --> 00:10:03,640
‫only to the actors in our particular Trace channel, such as the Gargoyle is the only one that we set

138
00:10:03,640 --> 00:10:04,420
‫up at the moment.

139
00:10:04,420 --> 00:10:06,880
‫So that's the only one that it's finding.

140
00:10:06,880 --> 00:10:08,770
‫I'll see you in the next lecture.

