‫Hello and welcome.
‫In this lecture, we're going to be learning to draw debug spheres in our scene so that we can visualize
‫different f vector locations in space.
‫Let's dive in and see how this works.
‫It's a very soon we're going to want to call our grab component at location with a rotation.
‫For this, we're going to need to know a couple of things which component we're trying to grab the location,
‫the rotation, in this case, the bone name we can happily ignore.
‫But we do need to know these other things.
‫So when it comes to the rotation, this is pretty straightforward because we can just take the rotation
‫of our component.
‫When it comes to the component, that's also quite straightforward.
‫All we have to do is take the component we collide with when when we're doing our sphere trace.
‫Now, the location, on the other hand, is a little bit more tricky because we don't just want to take
‫the location of the actual component, because I might be looking at it here, I might be expecting
‫to grab it by its head.
‫But if you see the root of this object, it's actually down near the base.
‫So it can lead to results that are a bit strange.
‫I grab it up near the top, near the wings, and it will then move the gargoyle up and float too high
‫so it doesn't feel right if you do it that way.
‫I've tried and it's just a bit odd.
‫So what we're going to do is we want to find where we hit this gargoyle when we do our sphere trace.
‫If we go over to our grab of CP, there's actually a couple of options in our hit result for getting
‫some vectors of location.
‫So if you do hit result dot and then hit a control space, you can see a bunch of different things in
‫here.
‫You can see that one of them is the component that we've hit.
‫We will be using that later on.
‫There is an impact point that could potentially be the interesting one.
‫There's also a location.
‫So to figure out whether it's the impact point or the location that I want, ideally we'd have some
‫way to visualize this in the world, visualize the point that we are trying to see.
‫And fortunately there is in the same include file that we found our drawing a debug line.
‫There is a draw debug sphere function as well and it has a lot of the same parameters.
‫You need a world as the first parameter, the center of the sphere.
‫The radius is a float, the number of segments that the sphere should have.
‫So we'll see what this means when we actually draw it.
‫Then there's a color and then whether it should persist in the scene and for how long, etc. So let's
‫have a go at drawing this sphere.
‫And initially I'm just going to use it to draw a sphere at the end point of our of our sweep.
‫So we're going to call draw debug sphere.
‫We don't have to include anything new because we've already got draw debug line in here.
‫Get World is going to be the first argument then the center of this sphere, which is going to be the
‫end vector, the radius.
‫I'm going to give it ten centimeters radius, I'm going to give it ten segments as well.
‫And then I'm going to have an F color this time.
‫Let's give it something different.
‫F color, colon, colon, maybe a blue sphere this time, persistent lines.
‫I do want this to be true because we call grab once, not every tic.
‫So I'm going to set this to true then the lifetime.
‫I'm going to set the sphere to last for 5 seconds and then the rest is less important.
‫I'm going to put a semicolon at the end of the line and recompile if we go ahead and hit play after
‫it's finished compiling and we'll move back a little bit from the gargoyle and I'm going to left click
‫and you can see the sphere appearing four meters in front of where I'm looking now.
‫I thought it would persist for 5 seconds, but actually what I need to put in here is not that persist
‫is true because that basically ignores the lifetime entirely and just keeps them around forever.
‫So if we put in false and then the time of 5 seconds.
‫So I just made a mistake there, which is easy to do and easy to misinterpret documentation and then
‫we go ahead and hit play in our game.
‫And if we create one of those spheres after 5 seconds, it disappears again.
‫So it won't be cluttering our world for too long.
‫So let's challenge you to figure out which location we need from our hit result.
‫Draw a debug sphere for each of them, the hit result location and the hit result impact point and use
‫different f colors to display it and make it clear which one is which and what's the difference?
‫Which one do we think we might need?
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫Let's go back into the code and go down into our if statement where we've got a hit marked out.
‫So we will have some sort of hit result.
‫And just before we get hold of the actor, what I'm going to do is draw debug sphere using Get World.
‫And the first location we're going to draw is the hit result location going to go for ten radius, ten
‫segments, f color, colon, colon green this time and persistent lines is going to be false and the
‫lifetime.
‫Let's make it 5 seconds and then let's copy this line because we want almost exactly the same thing,
‫except we want to change out.
‫Hit result location for hit result dot.
‫Impact point and the color.
‫Maybe we'll switch that out to be read so that we know the difference between the two green and red.
‫Let's compile and head over into the editor.
‫Let's hit play.
‫And you see that when I don't actually hit anything, I just get this blue sphere.
‫And if I go up to the gargoyle, look at the gargoyle and try and hit it.
‫Okay, we've got two very different points here.
‫The green one is quite far away from the gargoyle.
‫The red one is much closer.
‫So what's going on here?
‫Well, if we look at the hit result documentation and come down and have a look at what location is
‫meant to be, you can see a discussion here, that location in world space where the moving shape would
‫end up against the impacted object if there is a hit.
‫And if I eject and pause for a second to see what these points actually look like, you can see that
‫Green One does indeed match that description.
‫We have a one metre radius sphere that we are projecting or sweeping towards this gargoyle and it would
‫hit the gargoyle as soon as it gets to this green point here, because that's about a metre radius around
‫it, whereas the impact point tells us where that sphere hits the gargoyle.
‫Now, that is much more likely to be where we want to grab it because it's actually on the gargoyle.
‫If I grabbed it over here, the gargoyle would rotate and spin around some point randomly in midair
‫and not look like we're grabbing it at all.
‫Whereas around this red point it looks like I've just grabbed it by the wingtip and that would look
‫natural.
‫Great stuff.
‫So in this lecture, we have learned a little bit more about what's available from a hit result, and
‫we've learned how to draw some more debug objects in our scene.
‫I'll see you in the next lecture.