‫Hello and welcome.
‫In this lecture, we're going to make our mover do some moving by checking a checkbox.
‫We will enable it to move and move at a constant speed.
‫And we're going to be doing this using some library functions this time from within.
‫Unreal.
‫So it'll put all of our knowledge of header files and includes to the test.
‫Let's dive in and see how it works.
‫So the way I want this mover to work is that I want it to move smoothly from where it started to a target
‫offset over a period of a certain number of seconds.
‫So the way we're going to need to configure this is to add in some new properties into the header file.
‫So let's start off by adding a private section to the head of file and then we're going to add a new
‫property that's going to be edit anywhere, which is going to define the offset, the move offset.
‫So how far this mover should move when activated.
‫So the way we're going to do that is going to use an F vector and we're going to call it the move offset
‫like so I won't give it a default value.
‫We'll do that in the editor.
‫Then I'm going to create another new property which is again going to be edit anywhere, which is going
‫to be the amount of time it takes to move to the target.
‫So we're going to have that be a float, which is move time and I'm going to set that at a default value
‫of, say, 4 seconds.
‫Now, there's one more thing that I want to put in here, which is a Boolean just for now, which is
‫going to allow us to activate the mover so that it's going to move down when we activate this boolean.
‫So let's create another U property again.
‫Edit anywhere so that we can edit it even while we're playing and is going to be a boolean saying should
‫move and by default it's going to be set to false.
‫So when we check this off in the editor, when we're playing, it's going to go and move to its target
‫move offset.
‫Now previously when we had a moving component, we did all the steps manually.
‫But I want to show you that there's actually some functionality built in to do a lot of the calculations
‫we need.
‫It's built right into Unreal and there's a function called V interpret constant too.
‫And what's interesting about it, let's have a look at the remarks.
‫So interpolate a vector from a current vector to a target vector using a constant step.
‫So that means that over time it we're going to move from current to target at a certain speed and it's
‫going to do that constantly, which sounds like exactly what we want.
‫We want to move from our current location to a target offset location at a constant speed.
‫Now, you can see if you have a look at the syntax for this function, you can see that it has a return
‫type of F vector.
‫So that's the new location that it's interpolating.
‫Then it has two inputs.
‫We've got a current F vector and don't worry about the other symbols around this effect of for now we
‫just the important thing is that it is a current vector and then the target that we want it to eventually
‫reach.
‫Then it has the delta time.
‫So it uses this to make the movement frame rate independent and in the interpolation speed.
‫So how fast should we be moving from our current location to the target?
‫Now you will notice that up here in the documentation it actually has a section that says include and
‫this tells you the include line you're going to need in your C++ file in order to be able to use this
‫function.
‫And as we've seen in the previous video, the include line allows us to copy in the definitions from
‫this particular file.
‫And one of the definitions is the definition for this function.
‫So it allows us to use this V interpret constant to now the V in front of this function basically means
‫that it does interpolation on vectors.
‫That's why it's called V interpretation as opposed to other interpolation functions that are also available
‫in this library file.
‫So let's have a look at how we would use it.
‫First of all, we're going to copy the include line from the documentation and we're going to go over
‫into our move of CP where we want to implement this in the body of the tick component.
‫But they include we do not include within the body of the tick component.
‫We have to do the includes all at the top of the file.
‫So that's where I'm going to put mine and I'm going to put mine after the include of mover H.
‫So we're going to put in and include for math, forward slash, unreal math utility.
‫H Now what we can do is we can actually use the function within our tick component.
‫Let's just get rid of the code that we've already got into it.
‫Compute.
‫Because we were using that to understand how to call functions on other actors.
‫And what we need to do is if you scroll up, you can see the way to call this is F Mass Colon, Colon
‫V Intercept, constant two.
‫So we kind of doing this colon colon operator that looks inside the F math class, which organizes together
‫all these maths utilities.
‫So we're going to do F math.
‫Colon.
‫And here you can see a bunch of autocomplete coming up for different maths functions included in that
‫header file that we've just included into this file.
‫So you can have a look through, see any of the interesting stuff is in here, I can see a bunch of
‫interpolation, circular interpolations, etc. but we wanted the V interpret constant to and we can
‫hit tab to complete that and then open some parentheses and we can see the arguments that we need to
‫be passing in the current, the target delta time and the intercept speed.
‫So let's start creating some variables to hold some of these.
‫So first of all, we need an F vector which is going to be our current location and we're not going
‫to set that for just yet.
‫Then we're going to have an F vector for the target location, and then we're going to get a float for
‫the speed.
‫And we're going to have to calculate each of these individually to figure out how we can make this movement
‫happen.
‫So the current location is going to be relatively straightforward.
‫We need to get the current location of the owning actor.
‫So how do we do that?
‫Let's replace this semicolon with an equal sign.
‫Then we're going to do a get owner pair of parentheses.
‫Then we're going to do an arrow.
‫So we're going to be calling a function on the owning actor, and we're going to do get actor location
‫and then a pair of parentheses and a semicolon to end it.
‫So that gets us the current location of the owning actor.
‫Now, what about our target location?
‫Well, we know that we've got a property called the move offset, so that's going to be involved here.
‫But we do need to add the original location to this move offset.
‫So for that, we need to capture the original location in Biggin play.
‫So we need a variable to store it in.
‫So let's go over to our mover H and it's not going to be an edit anywhere.
‫Once I'm going to put it under our U.
‫Properties, it's going to be an F vector called Original Location.
‫We're not going to set it to anything here.
‫Then we're going to go over into our mover CP into begin play, remove this comment line and put our
‫own code, which is going to be that the original location is equal to get owner parentheses arrow get
‫actor location like so.
‫So now that we've got our original location captured and begin play, we can use it in TTIC.
‫So we go over into Tick and we set our target location equal to the original location plus the move
‫offset.
‫So that's our target location and finally our speed.
‫Well, this is essentially the distance that we need to move divided by the time which we need to move
‫over.
‫So if we've got a target location and we've got an original location, we need to find the distance
‫between these two, which we can do with an F vector, colon, colon distance.
‫Then we pass in to the parentheses, the original location and the target location.
‫So that gives us the distance between these two vectors.
‫And then we are going to divide that through by what did we have over and over called the move time.
‫So that gives us the speed at which we should be moving.
‫And now we can use these as arguments to have V intercept constant too.
‫So we've got first of all, we need to give it the current location and then the target location.
‫Then we're going to tell it the Delta time, which is just already a parameter in tick component.
‫So we just need to pass that through and then we've got the intercept speed.
‫So we're just going to pass in the speed like so put a semicolon on the end of that line and this is
‫essentially the new location.
‫So let's store that into a new variable F vector called new location equal to this cool.
‫Now we need to do something with that new location because it's no good just having calculated it,
‫we do actually need to move the actor to the new location.
‫So that's what we're going to do.
‫We're going to call it on get owner.
‫So we do a get own.
‫Parentheses Arrow.
‫And then we're going to do a set actor location and we're going to pass in the new location like so
‫and have a semicolon at the end of the line.
‫So let's go ahead and compile this and see if it works.
‫So if we go over into the dungeon, select the wall that we want to move, you can now see that the
‫mover component has got a move offset, which I'm going to want to do in the Z direction, and I think
‫I'm going to do -600.
‫And then the move time, 4 seconds should be just fine.
‫So let's save that and then hit play and see if it moves so it's not moving.
‫And there's an error in the output log saying that the mobility of the actor has been set to static,
‫which is why it can't move.
‫So if we select the actor again and we look at its mobility settings, you can see in fact the mobility
‫settings of the static mesh component.
‫So select the static mesh component, then look at the mobility.
‫You can see it's set to static, which basically means it's not allowed to move.
‫Let's switch that over to movable because we do want it to move and then let's go ahead and hit play.
‫Now you can see in the darkness that the wall was going down, which is perfect.
‫I do think we've got a mover somewhere else in our scene up on this pillar here that it's also trying
‫to move.
‫So let's not do that.
‫Let's delete the mover component that we added in there just for testing and it should give us no errors
‫in the output log.
‫If we go ahead and hit play now, we should just have that wall going down to its target location.
‫So let's challenge you to make it move with the boolean that we created that you property.
‫So you're going to wrap the code in an appropriate if statement and the appropriate code so that it
‫only moves the platform when that Boolean is true.
‫And then you're going to recompile the code and play and eject using F8 and then change the boolean
‫and observe the see whether it moves when you check that boolean.
‫So pause the video and have a go.
‫Okay.
‫Welcome back.
‫So let's go and wrap this tick component stuff in an if statement, not super, but everything else
‫we're going to do.
‫If should move, then open some parentheses and move all this code in remembering to indent it one level
‫because we're inside parentheses and we want to show that this would only be executed within the if
‫statement.
‫Make it easy for us to read control all f 11 to compile and then we should be able to go and hit play
‫and hit F eight to eject if we have got our mouse captured.
‫And then we're going to go in to have a look at our outlier, we're going to try and find the wall or
‫we can just click in the scene and then we're going to select our move a component and check should
‫move and they go, the wall starts to move when that happens.
‫Great stuff.
‫I will see you in the next lecture.