﻿1
00:00:04,340 --> 00:00:05,660
‫Hello and welcome.

2
00:00:05,660 --> 00:00:11,450
‫In this lecture we are going to be drawing debug lines into our scene so that we can visualize what

3
00:00:11,450 --> 00:00:16,790
‫it is that a line trace is doing or what it should be doing, and figure out if our values that we're

4
00:00:16,790 --> 00:00:18,490
‫calculating are correct.

5
00:00:18,500 --> 00:00:20,390
‫Let's dive in and have a look.

6
00:00:21,270 --> 00:00:28,180
‫So as we can see, our sweep multi bi channel function requires a start and an end vector.

7
00:00:28,200 --> 00:00:33,360
‫Now it can be a little bit hard to figure out what's going on with these functions when we actually

8
00:00:33,360 --> 00:00:34,020
‫use them.

9
00:00:34,140 --> 00:00:40,080
‫Because if you start using it and you don't get back the results you're expecting, you can sometimes

10
00:00:40,680 --> 00:00:43,350
‫leave yourself wondering, Well, did I ask the right question in the first place?

11
00:00:43,350 --> 00:00:46,620
‫Did I send in the right start and end vectors even?

12
00:00:46,830 --> 00:00:52,500
‫Well, to figure that out, what we're going to do is use another function here called the draw debug

13
00:00:52,500 --> 00:00:59,070
‫line so that we can definitely see where the start and end vectors are, basically by drawing a line

14
00:00:59,070 --> 00:01:05,520
‫between them and given this is exactly the kind of thing that's going to be done by our sweep, then

15
00:01:05,520 --> 00:01:11,610
‫this is a good way of seeing, first of all, whether we've got the right inputs in in the first place.

16
00:01:11,850 --> 00:01:17,520
‫So you can see here that the draw debug line requires quite a few arguments, but not all of them are

17
00:01:17,520 --> 00:01:18,630
‫actually required.

18
00:01:19,170 --> 00:01:23,000
‫Only the first three, four or five.

19
00:01:23,010 --> 00:01:26,490
‫So we've got the first thing that comes in is a new world.

20
00:01:26,550 --> 00:01:28,260
‫We know how to get hold of the world.

21
00:01:28,260 --> 00:01:31,650
‫Now we've got then the line start, which is in a vector.

22
00:01:31,650 --> 00:01:36,450
‫We've got a line end again, which is a vector, then an F colour, which is something we haven't come

23
00:01:36,450 --> 00:01:38,910
‫across before, but you can click on it to find out what it is.

24
00:01:39,090 --> 00:01:46,140
‫And essentially it is a type like F vector that represents colours and there are a few handy colours

25
00:01:46,140 --> 00:01:52,260
‫already built in for us that allow us to just say, Hey, we want a black, we want blue, green, whatever.

26
00:01:52,260 --> 00:01:57,660
‫You can just use a colour name rather than having to specify the R, g b values.

27
00:01:57,660 --> 00:02:04,110
‫And then the final few through here are whether we've got the persistent lines, which tells us whether

28
00:02:04,110 --> 00:02:08,790
‫the line sticks around or whether it goes away at the end of the frame tells us the lifetime.

29
00:02:08,790 --> 00:02:14,700
‫So how many seconds does it stick around for the depth priority and the thickness, which neither of

30
00:02:14,700 --> 00:02:16,170
‫which we will be using?

31
00:02:16,470 --> 00:02:21,840
‫So the other useful piece of information on this documentation page is the include.

32
00:02:21,840 --> 00:02:26,610
‫So you can see here to use this function, we need to be using the header file that declares it, which

33
00:02:26,610 --> 00:02:29,730
‫is the hash include draw debug helpers.

34
00:02:29,730 --> 00:02:34,320
‫So let's go ahead and get that first of all, because that's going to make sure that autocomplete works

35
00:02:34,320 --> 00:02:35,010
‫in Visual Studio.

36
00:02:35,010 --> 00:02:40,110
‫If you don't have the header files, then Visual Studio doesn't actually know how to auto complete these

37
00:02:40,110 --> 00:02:40,890
‫functions.

38
00:02:40,890 --> 00:02:47,880
‫Then we're going to go down in to tick component and I am going to get rid of our log message for the

39
00:02:47,880 --> 00:02:48,960
‫get well get time.

40
00:02:48,960 --> 00:02:51,330
‫We'll get rid of all of this time, in fact.

41
00:02:51,330 --> 00:02:52,650
‫And you know what?

42
00:02:52,650 --> 00:02:58,830
‫We're just going to empty out our tick function, everything after our super colon, colon tick component

43
00:02:58,830 --> 00:03:04,920
‫we're going to remove and we're going to start with the draw debug line.

44
00:03:04,920 --> 00:03:09,120
‫So draw debug line and then open some parentheses.

45
00:03:09,120 --> 00:03:16,170
‫If you hit a control space, then you can see the parameters we were just talking about and some more

46
00:03:16,170 --> 00:03:19,920
‫information that wasn't available there, such as their default values.

47
00:03:19,920 --> 00:03:24,180
‫Some of them have default values, particularly after persistent lines.

48
00:03:24,180 --> 00:03:25,530
‫You can see the default value is false.

49
00:03:25,530 --> 00:03:31,500
‫So you don't actually have to provide an argument if it has a default value, but you can see that the

50
00:03:31,500 --> 00:03:33,090
‫colour doesn't have a default value.

51
00:03:33,090 --> 00:03:36,120
‫So we do need to provide everything up to that point.

52
00:03:36,600 --> 00:03:39,180
‫So the first thing is the world little mini challenge.

53
00:03:39,180 --> 00:03:42,900
‫How do you get hold of and pass in the world into draw debug line.

54
00:03:43,990 --> 00:03:51,340
‫You do a get world parentheses like so then we're going to need a start and an end.

55
00:03:51,340 --> 00:03:56,290
‫So for that I'm going to create two variables just before draw debug line and I'm not going to fill

56
00:03:56,290 --> 00:03:56,920
‫them out just yet.

57
00:03:56,920 --> 00:04:07,390
‫So if vector start and F vector end and those are going to be our next two parameter start and end,

58
00:04:07,390 --> 00:04:13,990
‫and then we need to give a color to do the color we can do F color, colon, colon, and then we can

59
00:04:13,990 --> 00:04:20,500
‫use one of those predefined colors such as red is always a good one.

60
00:04:20,500 --> 00:04:21,580
‫You can easily see it.

61
00:04:21,580 --> 00:04:26,320
‫And then in this case, because we're doing it in tick and we're doing every frame, we're writing this

62
00:04:26,320 --> 00:04:31,930
‫line to the screen, we can just use the persistent lines equals false.

63
00:04:31,930 --> 00:04:38,860
‫So every ticket will be redrawing this debug line, close the parentheses and then we can put the semicolon

64
00:04:38,860 --> 00:04:40,300
‫at the end of the line.

65
00:04:40,300 --> 00:04:44,230
‫So what are these start and end values going to look like?

66
00:04:44,590 --> 00:04:51,490
‫Well, at the start, it's literally just going to be the location of our grabber component because

67
00:04:51,490 --> 00:04:55,810
‫that's going to be attached to the camera and that is a good start location.

68
00:04:55,810 --> 00:05:02,320
‫Now remember that there is a forward vector for this component, for the camera, for the grabber,

69
00:05:02,410 --> 00:05:09,070
‫and that forward direction is going to be pointing out from the camera out into the scene, always pointing

70
00:05:09,070 --> 00:05:09,730
‫forward.

71
00:05:09,730 --> 00:05:19,000
‫So what we want to do is take our start vector, add the forward vector multiplied by some amount.

72
00:05:19,000 --> 00:05:25,180
‫Basically that's some amount is going to be the maximum distance that we are going to look for the object.

73
00:05:25,180 --> 00:05:31,990
‫So you might have one or two or three meters as the amount and then we're going to end up with an end

74
00:05:31,990 --> 00:05:32,440
‫vector.

75
00:05:32,440 --> 00:05:39,520
‫So the start plus the forward vector of the grabber is going to equal the end vector.

76
00:05:39,520 --> 00:05:45,580
‫So that maximum depth that we want to look into the scene is something that we might want to configure.

77
00:05:45,580 --> 00:05:48,580
‫So we'll put it as a you property on the grabber.

78
00:05:49,450 --> 00:05:55,180
‫Let's go over to the grabber door H and create a private section, make a U property that we're going

79
00:05:55,180 --> 00:06:03,040
‫to make edit anywhere and then we're going to have the type B of float so that it can be any numerical

80
00:06:03,040 --> 00:06:03,850
‫distance.

81
00:06:04,120 --> 00:06:12,400
‫And we're going to call this the max grab distance and we'll set it to a distance of four meters by

82
00:06:12,400 --> 00:06:12,850
‫default.

83
00:06:12,850 --> 00:06:18,460
‫Maybe that will have to be 400 because the default unit is centimeters.

84
00:06:18,460 --> 00:06:22,330
‫So I'd like to challenge you to calculate those starts and ends.

85
00:06:22,330 --> 00:06:30,580
‫Use the get component location in the first instance, use the get forward vector to calculate end and

86
00:06:30,580 --> 00:06:35,560
‫multiply by the max grab distance that we've just configured there.

87
00:06:35,590 --> 00:06:41,170
‫Then compile, play and eject from your actor because this line is going to be going straight down the

88
00:06:41,170 --> 00:06:41,470
‫camera.

89
00:06:41,470 --> 00:06:42,790
‫You may not see it initially.

90
00:06:42,790 --> 00:06:43,570
‫So eject.

91
00:06:43,630 --> 00:06:49,420
‫Come and step out of your own body and can you see the line pause, video and have a go.

92
00:06:52,800 --> 00:06:53,280
‫Okay.

93
00:06:53,280 --> 00:06:53,910
‫Welcome back.

94
00:06:53,910 --> 00:06:59,010
‫So let's go into the grab a EP and start writing what we're going to put in start.

95
00:06:59,460 --> 00:07:05,640
‫As we've said, there's simply just going to be the get component location and then the start.

96
00:07:05,670 --> 00:07:18,360
‫The end rather is going to be the start, plus the get forward vector multiplied by the max grab distance

97
00:07:18,360 --> 00:07:21,090
‫like so put a semicolon on the end of that line.

98
00:07:21,090 --> 00:07:27,930
‫We're going to go ahead and compile and if it compiles successfully, let's go ahead and hit play and

99
00:07:27,930 --> 00:07:32,820
‫then get our mass in the viewport hit f eight to eject out.

100
00:07:32,820 --> 00:07:39,900
‫And if we step out of ourselves, you can see the line clear as day coming from where our camera was

101
00:07:39,930 --> 00:07:42,270
‫all the way down into the floor.

102
00:07:42,270 --> 00:07:47,460
‫And probably if I come out, we may even be able to see that it's poking a little bit out of the bottom

103
00:07:47,460 --> 00:07:48,600
‫of the floor as well.

104
00:07:48,600 --> 00:07:50,160
‫That's four meters for you.

105
00:07:50,160 --> 00:07:52,410
‫So we've got a start, we've got an end.

106
00:07:52,410 --> 00:07:59,580
‫And if we were to use this line, this would be an excellent one for the input parameters to our geometry

107
00:07:59,580 --> 00:08:02,520
‫sweep that we're going to be using later on.

108
00:08:02,520 --> 00:08:03,120
‫Great stuff.

109
00:08:03,120 --> 00:08:06,690
‫We've learnt how to draw debug lines into our scene.

110
00:08:06,690 --> 00:08:11,610
‫This is a very useful skill that you'll use a lot when you can't understand why something is not working.

111
00:08:11,610 --> 00:08:12,510
‫I hope you enjoyed it.

112
00:08:12,510 --> 00:08:14,070
‫I'll see you in the next lecture.

