‫Hello and welcome.
‫In this lecture we are going to be drawing debug lines into our scene so that we can visualize what
‫it is that a line trace is doing or what it should be doing, and figure out if our values that we're
‫calculating are correct.
‫Let's dive in and have a look.
‫So as we can see, our sweep multi bi channel function requires a start and an end vector.
‫Now it can be a little bit hard to figure out what's going on with these functions when we actually
‫use them.
‫Because if you start using it and you don't get back the results you're expecting, you can sometimes
‫leave yourself wondering, Well, did I ask the right question in the first place?
‫Did I send in the right start and end vectors even?
‫Well, to figure that out, what we're going to do is use another function here called the draw debug
‫line so that we can definitely see where the start and end vectors are, basically by drawing a line
‫between them and given this is exactly the kind of thing that's going to be done by our sweep, then
‫this is a good way of seeing, first of all, whether we've got the right inputs in in the first place.
‫So you can see here that the draw debug line requires quite a few arguments, but not all of them are
‫actually required.
‫Only the first three, four or five.
‫So we've got the first thing that comes in is a new world.
‫We know how to get hold of the world.
‫Now we've got then the line start, which is in a vector.
‫We've got a line end again, which is a vector, then an F colour, which is something we haven't come
‫across before, but you can click on it to find out what it is.
‫And essentially it is a type like F vector that represents colours and there are a few handy colours
‫already built in for us that allow us to just say, Hey, we want a black, we want blue, green, whatever.
‫You can just use a colour name rather than having to specify the R, g b values.
‫And then the final few through here are whether we've got the persistent lines, which tells us whether
‫the line sticks around or whether it goes away at the end of the frame tells us the lifetime.
‫So how many seconds does it stick around for the depth priority and the thickness, which neither of
‫which we will be using?
‫So the other useful piece of information on this documentation page is the include.
‫So you can see here to use this function, we need to be using the header file that declares it, which
‫is the hash include draw debug helpers.
‫So let's go ahead and get that first of all, because that's going to make sure that autocomplete works
‫in Visual Studio.
‫If you don't have the header files, then Visual Studio doesn't actually know how to auto complete these
‫functions.
‫Then we're going to go down in to tick component and I am going to get rid of our log message for the
‫get well get time.
‫We'll get rid of all of this time, in fact.
‫And you know what?
‫We're just going to empty out our tick function, everything after our super colon, colon tick component
‫we're going to remove and we're going to start with the draw debug line.
‫So draw debug line and then open some parentheses.
‫If you hit a control space, then you can see the parameters we were just talking about and some more
‫information that wasn't available there, such as their default values.
‫Some of them have default values, particularly after persistent lines.
‫You can see the default value is false.
‫So you don't actually have to provide an argument if it has a default value, but you can see that the
‫colour doesn't have a default value.
‫So we do need to provide everything up to that point.
‫So the first thing is the world little mini challenge.
‫How do you get hold of and pass in the world into draw debug line.
‫You do a get world parentheses like so then we're going to need a start and an end.
‫So for that I'm going to create two variables just before draw debug line and I'm not going to fill
‫them out just yet.
‫So if vector start and F vector end and those are going to be our next two parameter start and end,
‫and then we need to give a color to do the color we can do F color, colon, colon, and then we can
‫use one of those predefined colors such as red is always a good one.
‫You can easily see it.
‫And then in this case, because we're doing it in tick and we're doing every frame, we're writing this
‫line to the screen, we can just use the persistent lines equals false.
‫So every ticket will be redrawing this debug line, close the parentheses and then we can put the semicolon
‫at the end of the line.
‫So what are these start and end values going to look like?
‫Well, at the start, it's literally just going to be the location of our grabber component because
‫that's going to be attached to the camera and that is a good start location.
‫Now remember that there is a forward vector for this component, for the camera, for the grabber,
‫and that forward direction is going to be pointing out from the camera out into the scene, always pointing
‫forward.
‫So what we want to do is take our start vector, add the forward vector multiplied by some amount.
‫Basically that's some amount is going to be the maximum distance that we are going to look for the object.
‫So you might have one or two or three meters as the amount and then we're going to end up with an end
‫vector.
‫So the start plus the forward vector of the grabber is going to equal the end vector.
‫So that maximum depth that we want to look into the scene is something that we might want to configure.
‫So we'll put it as a you property on the grabber.
‫Let's go over to the grabber door H and create a private section, make a U property that we're going
‫to make edit anywhere and then we're going to have the type B of float so that it can be any numerical
‫distance.
‫And we're going to call this the max grab distance and we'll set it to a distance of four meters by
‫default.
‫Maybe that will have to be 400 because the default unit is centimeters.
‫So I'd like to challenge you to calculate those starts and ends.
‫Use the get component location in the first instance, use the get forward vector to calculate end and
‫multiply by the max grab distance that we've just configured there.
‫Then compile, play and eject from your actor because this line is going to be going straight down the
‫camera.
‫You may not see it initially.
‫So eject.
‫Come and step out of your own body and can you see the line pause, video and have a go.
‫Okay.
‫Welcome back.
‫So let's go into the grab a EP and start writing what we're going to put in start.
‫As we've said, there's simply just going to be the get component location and then the start.
‫The end rather is going to be the start, plus the get forward vector multiplied by the max grab distance
‫like so put a semicolon on the end of that line.
‫We're going to go ahead and compile and if it compiles successfully, let's go ahead and hit play and
‫then get our mass in the viewport hit f eight to eject out.
‫And if we step out of ourselves, you can see the line clear as day coming from where our camera was
‫all the way down into the floor.
‫And probably if I come out, we may even be able to see that it's poking a little bit out of the bottom
‫of the floor as well.
‫That's four meters for you.
‫So we've got a start, we've got an end.
‫And if we were to use this line, this would be an excellent one for the input parameters to our geometry
‫sweep that we're going to be using later on.
‫Great stuff.
‫We've learnt how to draw debug lines into our scene.
‫This is a very useful skill that you'll use a lot when you can't understand why something is not working.
‫I hope you enjoyed it.
‫I'll see you in the next lecture.