‫Hello and welcome.
‫In this lecture we're going to be introducing member functions and this get safe and normal function
‫that will allow us to get hold of the direction of a particular vector.
‫Let's dive in and see how this works.
‫So our simple method for sending the platform back in the opposite direction is working at the speeds
‫we've tested it out at.
‫But what happens if I say, Hey, let's make this platform go ten times faster?
‫Let's go ahead and play and see what happens.
‫Well, suddenly that platforms jump forward quite a lot and it's not hovering around the same location
‫as it was before.
‫And the reason for this is because the current location, when we set it as the start location, isn't
‫necessarily exactly the distance moved, we could have overshot.
‫And that is captured here in the if statement.
‫We're saying that the distance moved is greater than the move distance, which means that we will have
‫overshot.
‫We have to have overshot in order to have triggered this if statement.
‫But the question is by how much, and that's going to depend very much on how large the Delta time is.
‫We can overshoot by quite large amounts, especially if the platform velocity is large, which means
‫that our start location may drift over time.
‫It may not stay constant.
‫So the better way to do this would be to calculate how far we need to move from the original start location
‫to get to the new one using the exact move distance.
‫So let's try and visualize this back and forth calculation.
‫We're saying we've got a platform at its start location over here.
‫We say it's got a velocity which we can represent with an arrow that is a direction and a size, and
‫it's also got a distance that we want it to move.
‫We'll just represent it by this brace here.
‫Now, what we're saying is we would like to figure out the exact point where the platform would be at
‫the end, not overshot, but just exactly the end location.
‫Now, the way we can do this is by taking the direction of that velocity arrow.
‫So in vector parlance, this is called the normal of the arrow, and it basically takes it down to being
‫of size one.
‫So we get the direction but a size of one.
‫So that allows us to know this count, essentially the size of the velocity, how fast we're going.
‫And then what we can do is we can multiply that direction by the quantity of our distance to give us
‫an arrow that gives us the whole movement from the start location right to the end location.
‫Exactly.
‫So let's have a look at how we can do this in C++.
‫What we're looking for is a new start location.
‫So let's remove how we're currently doing this and we're going to have a start location equal to, well,
‫what is it going to be equal to?
‫Well, it's going to be equal to, first of all, the start location plus something, because we're
‫starting from here and we're adding this green vector to get to the end.
‫So what's that green vector there?
‫Well, that's where we need to get the normal of the platform velocity.
‫And just to make it easier for us to understand, I'm going to split that into its own variable.
‫So we're going to create a new variable of type F vector, which I am going to call the move direction,
‫just to make it super clear what it is that we're trying to store in it and then we're going to get
‫this from the platform velocity dot, get safe, normal and then some parentheses around the end.
‫So what's going on here?
‫We haven't seen this before.
‫We've used Dot to get hold of the components of the vector, the X, Y and Z.
‫Those were variables.
‫But in C++ and in object oriented programming in general, we also have functions that exist on classes,
‫so we can use the DOT operator to get hold of one of those.
‫We've used the colon colon when we've been trying to get it out of the class itself.
‫But when we want to do an operation with the actual vector itself, so platform velocities vector,
‫we can use the dot operator to get the normal of that vector.
‫So that's what we're doing here, using a member function instead of a member variable.
‫So we've got the safe normal of that platform velocity and we'll put semicolon at the end of the line
‫because here we've got a variable that's essentially we're saying that's the move direction.
‫So now we can use that in the subsequent line to do a move direction multiplied by the move distance
‫that's configured because we want to move exactly to the end, not overshoot.
‫And then after we've done that, we should actually move our platform to the end location.
‫So we're going to do a set actor location to be the start location, because otherwise our platform
‫will have overshot and gone past that end location because we'll have updated it with the current location,
‫which is the overshot location.
‫So that allows us to move exactly to the end point.
‫And then start from that new starting location.
‫Now it's important that we update the platform velocity after we do all of this because we're using
‫it to get hold of the move direction.
‫So I'm going to update the platform velocity after we set the actor location.
‫Now let's go back into one reel and hit compile and see if this is fixed.
‫The problem with our platform moving backwards and forwards, let's close down this terminal and hit
‫play.
‫And now if we have a look, the platform is moving quickly, but it is moving reliably around the start
‫and end location we would expect.
‫So that's all I wanted to cover in this lecture.
‫We just corrected a little bit of a bug that could have cropped up for some of our platform configurations.
‫I'll see you in the next one.