﻿1
00:00:04,340 --> 00:00:05,480
‫Hello and welcome.

2
00:00:05,480 --> 00:00:10,550
‫In this lecture, we're going to be learning to draw debug spheres in our scene so that we can visualize

3
00:00:10,550 --> 00:00:13,520
‫different f vector locations in space.

4
00:00:13,520 --> 00:00:15,830
‫Let's dive in and see how this works.

5
00:00:16,690 --> 00:00:22,510
‫It's a very soon we're going to want to call our grab component at location with a rotation.

6
00:00:22,510 --> 00:00:28,660
‫For this, we're going to need to know a couple of things which component we're trying to grab the location,

7
00:00:28,660 --> 00:00:32,200
‫the rotation, in this case, the bone name we can happily ignore.

8
00:00:32,200 --> 00:00:35,110
‫But we do need to know these other things.

9
00:00:35,320 --> 00:00:40,480
‫So when it comes to the rotation, this is pretty straightforward because we can just take the rotation

10
00:00:40,480 --> 00:00:41,710
‫of our component.

11
00:00:41,710 --> 00:00:43,960
‫When it comes to the component, that's also quite straightforward.

12
00:00:43,960 --> 00:00:49,960
‫All we have to do is take the component we collide with when when we're doing our sphere trace.

13
00:00:49,960 --> 00:00:54,340
‫Now, the location, on the other hand, is a little bit more tricky because we don't just want to take

14
00:00:54,340 --> 00:01:00,580
‫the location of the actual component, because I might be looking at it here, I might be expecting

15
00:01:00,580 --> 00:01:02,080
‫to grab it by its head.

16
00:01:02,080 --> 00:01:06,580
‫But if you see the root of this object, it's actually down near the base.

17
00:01:06,580 --> 00:01:09,280
‫So it can lead to results that are a bit strange.

18
00:01:09,280 --> 00:01:17,110
‫I grab it up near the top, near the wings, and it will then move the gargoyle up and float too high

19
00:01:17,230 --> 00:01:19,780
‫so it doesn't feel right if you do it that way.

20
00:01:19,780 --> 00:01:21,910
‫I've tried and it's just a bit odd.

21
00:01:22,300 --> 00:01:29,920
‫So what we're going to do is we want to find where we hit this gargoyle when we do our sphere trace.

22
00:01:29,920 --> 00:01:35,680
‫If we go over to our grab of CP, there's actually a couple of options in our hit result for getting

23
00:01:35,680 --> 00:01:37,750
‫some vectors of location.

24
00:01:37,750 --> 00:01:44,230
‫So if you do hit result dot and then hit a control space, you can see a bunch of different things in

25
00:01:44,230 --> 00:01:44,890
‫here.

26
00:01:44,950 --> 00:01:47,050
‫You can see that one of them is the component that we've hit.

27
00:01:47,050 --> 00:01:48,790
‫We will be using that later on.

28
00:01:48,790 --> 00:01:53,860
‫There is an impact point that could potentially be the interesting one.

29
00:01:53,860 --> 00:01:55,840
‫There's also a location.

30
00:01:55,840 --> 00:02:01,360
‫So to figure out whether it's the impact point or the location that I want, ideally we'd have some

31
00:02:01,360 --> 00:02:06,910
‫way to visualize this in the world, visualize the point that we are trying to see.

32
00:02:06,910 --> 00:02:12,850
‫And fortunately there is in the same include file that we found our drawing a debug line.

33
00:02:12,850 --> 00:02:18,550
‫There is a draw debug sphere function as well and it has a lot of the same parameters.

34
00:02:18,550 --> 00:02:22,300
‫You need a world as the first parameter, the center of the sphere.

35
00:02:22,330 --> 00:02:26,920
‫The radius is a float, the number of segments that the sphere should have.

36
00:02:26,920 --> 00:02:29,950
‫So we'll see what this means when we actually draw it.

37
00:02:29,950 --> 00:02:35,680
‫Then there's a color and then whether it should persist in the scene and for how long, etc. So let's

38
00:02:35,680 --> 00:02:38,710
‫have a go at drawing this sphere.

39
00:02:38,710 --> 00:02:46,660
‫And initially I'm just going to use it to draw a sphere at the end point of our of our sweep.

40
00:02:46,720 --> 00:02:52,270
‫So we're going to call draw debug sphere.

41
00:02:52,300 --> 00:02:56,500
‫We don't have to include anything new because we've already got draw debug line in here.

42
00:02:56,650 --> 00:03:01,420
‫Get World is going to be the first argument then the center of this sphere, which is going to be the

43
00:03:01,420 --> 00:03:03,850
‫end vector, the radius.

44
00:03:03,850 --> 00:03:08,800
‫I'm going to give it ten centimeters radius, I'm going to give it ten segments as well.

45
00:03:08,920 --> 00:03:12,100
‫And then I'm going to have an F color this time.

46
00:03:12,100 --> 00:03:13,060
‫Let's give it something different.

47
00:03:13,060 --> 00:03:17,830
‫F color, colon, colon, maybe a blue sphere this time, persistent lines.

48
00:03:17,830 --> 00:03:21,700
‫I do want this to be true because we call grab once, not every tic.

49
00:03:21,700 --> 00:03:25,060
‫So I'm going to set this to true then the lifetime.

50
00:03:25,060 --> 00:03:31,750
‫I'm going to set the sphere to last for 5 seconds and then the rest is less important.

51
00:03:31,750 --> 00:03:37,450
‫I'm going to put a semicolon at the end of the line and recompile if we go ahead and hit play after

52
00:03:37,450 --> 00:03:44,020
‫it's finished compiling and we'll move back a little bit from the gargoyle and I'm going to left click

53
00:03:44,020 --> 00:03:48,940
‫and you can see the sphere appearing four meters in front of where I'm looking now.

54
00:03:48,940 --> 00:03:54,550
‫I thought it would persist for 5 seconds, but actually what I need to put in here is not that persist

55
00:03:54,550 --> 00:03:59,560
‫is true because that basically ignores the lifetime entirely and just keeps them around forever.

56
00:03:59,560 --> 00:04:03,490
‫So if we put in false and then the time of 5 seconds.

57
00:04:03,490 --> 00:04:08,200
‫So I just made a mistake there, which is easy to do and easy to misinterpret documentation and then

58
00:04:08,200 --> 00:04:10,810
‫we go ahead and hit play in our game.

59
00:04:11,230 --> 00:04:16,870
‫And if we create one of those spheres after 5 seconds, it disappears again.

60
00:04:16,870 --> 00:04:19,840
‫So it won't be cluttering our world for too long.

61
00:04:19,840 --> 00:04:24,970
‫So let's challenge you to figure out which location we need from our hit result.

62
00:04:24,970 --> 00:04:32,440
‫Draw a debug sphere for each of them, the hit result location and the hit result impact point and use

63
00:04:32,440 --> 00:04:38,350
‫different f colors to display it and make it clear which one is which and what's the difference?

64
00:04:38,350 --> 00:04:40,500
‫Which one do we think we might need?

65
00:04:40,510 --> 00:04:42,460
‫Pause the video and have a go.

66
00:04:45,760 --> 00:04:46,390
‫Okay.

67
00:04:46,390 --> 00:04:47,320
‫Welcome back.

68
00:04:47,320 --> 00:04:53,650
‫Let's go back into the code and go down into our if statement where we've got a hit marked out.

69
00:04:53,650 --> 00:04:55,930
‫So we will have some sort of hit result.

70
00:04:55,990 --> 00:05:06,370
‫And just before we get hold of the actor, what I'm going to do is draw debug sphere using Get World.

71
00:05:07,000 --> 00:05:15,670
‫And the first location we're going to draw is the hit result location going to go for ten radius, ten

72
00:05:15,670 --> 00:05:24,670
‫segments, f color, colon, colon green this time and persistent lines is going to be false and the

73
00:05:24,670 --> 00:05:25,510
‫lifetime.

74
00:05:25,510 --> 00:05:31,240
‫Let's make it 5 seconds and then let's copy this line because we want almost exactly the same thing,

75
00:05:31,240 --> 00:05:32,650
‫except we want to change out.

76
00:05:32,650 --> 00:05:36,070
‫Hit result location for hit result dot.

77
00:05:36,950 --> 00:05:39,940
‫Impact point and the color.

78
00:05:39,950 --> 00:05:45,920
‫Maybe we'll switch that out to be read so that we know the difference between the two green and red.

79
00:05:45,950 --> 00:05:49,010
‫Let's compile and head over into the editor.

80
00:05:49,040 --> 00:05:50,360
‫Let's hit play.

81
00:05:50,570 --> 00:05:55,670
‫And you see that when I don't actually hit anything, I just get this blue sphere.

82
00:05:56,060 --> 00:05:59,380
‫And if I go up to the gargoyle, look at the gargoyle and try and hit it.

83
00:05:59,390 --> 00:06:02,690
‫Okay, we've got two very different points here.

84
00:06:02,720 --> 00:06:05,990
‫The green one is quite far away from the gargoyle.

85
00:06:06,020 --> 00:06:08,300
‫The red one is much closer.

86
00:06:08,300 --> 00:06:09,660
‫So what's going on here?

87
00:06:09,680 --> 00:06:15,650
‫Well, if we look at the hit result documentation and come down and have a look at what location is

88
00:06:15,650 --> 00:06:23,510
‫meant to be, you can see a discussion here, that location in world space where the moving shape would

89
00:06:23,510 --> 00:06:28,490
‫end up against the impacted object if there is a hit.

90
00:06:28,490 --> 00:06:34,740
‫And if I eject and pause for a second to see what these points actually look like, you can see that

91
00:06:34,790 --> 00:06:37,550
‫Green One does indeed match that description.

92
00:06:37,550 --> 00:06:45,200
‫We have a one metre radius sphere that we are projecting or sweeping towards this gargoyle and it would

93
00:06:45,200 --> 00:06:52,040
‫hit the gargoyle as soon as it gets to this green point here, because that's about a metre radius around

94
00:06:52,040 --> 00:06:57,350
‫it, whereas the impact point tells us where that sphere hits the gargoyle.

95
00:06:57,380 --> 00:07:02,270
‫Now, that is much more likely to be where we want to grab it because it's actually on the gargoyle.

96
00:07:02,270 --> 00:07:08,030
‫If I grabbed it over here, the gargoyle would rotate and spin around some point randomly in midair

97
00:07:08,030 --> 00:07:09,980
‫and not look like we're grabbing it at all.

98
00:07:09,980 --> 00:07:15,140
‫Whereas around this red point it looks like I've just grabbed it by the wingtip and that would look

99
00:07:15,140 --> 00:07:15,970
‫natural.

100
00:07:15,980 --> 00:07:16,520
‫Great stuff.

101
00:07:16,520 --> 00:07:21,710
‫So in this lecture, we have learned a little bit more about what's available from a hit result, and

102
00:07:21,710 --> 00:07:26,640
‫we've learned how to draw some more debug objects in our scene.

103
00:07:26,660 --> 00:07:28,220
‫I'll see you in the next lecture.

