‫Hello and welcome.
‫In this lecture, we're going to be looking at hooking up our character movement so that we can move
‫forward strife and look around our world.
‫The classics of moving around in a first person or third person shooter.
‫Let's dive in and see how it's done.
‫So continuing along in the vein of trying to get our character movement working, we are first of all
‫going to want to bind some input, but we're also going to know want to know what to bind that input
‫to.
‫Fortunately, when it comes to characters, there's a lot of simplifying stuff going on for us.
‫After all, Unreal really is an engine that's optimized for making things like shooter games, character
‫games.
‫And let's have a look at some of the movement functions that are already provided for us by the character
‫actor class, not just the character movement component, but also the character actor class provides
‫these and often passes a lot of this on to the character movement component, but not necessarily so.
‫Let's see what movement functions we're going to be dealing with.
‫First of all, there is going to be add movement input.
‫Add movement input basically takes a vector and tells you which direction you're going to move in.
‫So if it's a forward vector, you move forward.
‫If it's a backwards vector, you move backwards.
‫If it's a right vector, you move right and so on.
‫And the size of the vector is going to determine how fast you move in that direction.
‫The next thing is we've got add controller pitch input.
‫So that's about looking up and down, which is obviously very useful.
‫When you've got your mouse, you want to be looking up and down by moving your mouse up and down.
‫Then there's add controller, your input which is going left and right.
‫And finally there is a jump function which is just that maybe you hit the spacebar and you jump.
‫So with these things in mind, what we want to go ahead and do is create some bindings in our character
‫actor class that bind some input.
‫So some inputs from your keyboard, your mouse, your controller to these functions.
‫So we're going to do a few and then we're going to do a challenge to do the rest.
‫So let's go over to Visual Studio code and I'm in my shooter character.
‫H and we notice that we've got already here the set up player input component function.
‫This is where we need to bind our input.
‫Going to hit F12 to go over to the C++.
‫I'm going to hit Alt oh to go over to the C++ and find where we've got that set up.
‫So the first thing is it gives us this input component that we want to bind with.
‫If you remember, this is the way we do it.
‫We have a player input component, we use the arrow operator and we then do a bind function here.
‫So it's either a bind access or it's going to be a bind action depending on whether it's a discrete
‫action such as jump or whether it is an action that has a value such as looking up and down or moving.
‫Now, even when we do movement with a key, we still tend to bind it using an axis.
‫So I'm actually going to be making a bit of a typo for the first part of this video.
‫I will correct it later on, but do go ahead and use the bind axis instead of bind action here.
‫So really to take a step even further back, we need to go ahead and set up these actions and axes in
‫our project settings.
‫So let's go back over into Unreal.
‫Go to settings, project settings, and then I'm going to dock this down so we can see it very clearly
‫and we're going to go to the input section.
‫So engine input and set up some axes mappings and some action mappings.
‫So the ones I'm going to deal with right off the bat are the axes mappings for we're going to have,
‫first of all, a move forward.
‫And we're going to have also a look up.
‫Now, remember, we don't have a move forward and a move backwards because we can just do that with
‫negative scale.
‫So, for example, I want to set up my W Quay to be my move forward.
‫So that is scale one.
‫But if I want my se key to be my move back, I can still use move forward, but give it the scale of
‫minus one.
‫Just a quick reminder for you.
‫Same with look up.
‫I'm going to be using the mouse for this.
‫We'll cover controller input in the next lecture.
‫We're going to use the mouse y.
‫Now, remember, y is the one that goes up and down rather than left and right because it's kind of
‫a bit taller, isn't it?
‫A Y is a little bit of a taller letter than an X.
‫That's how I remember it anyway.
‫So Mouse Y is up and down and then we'll have to tweak with the scale, see whether it's going in the
‫right direction.
‫But basically this will give us negative values if we're going down and positive values if we're going
‫up.
‫So we may need to tweak with look up to see whether this is going to go in the right direction.
‫But you get the idea we can either invert the scale or not, depending on the type of input that's coming
‫in here.
‫So once we got the axis name, we can go back into the C++.
‫We're going to bind it using the text macro and the text of the axis name.
‫Then we need to say who we're going to call the function on and what function we're going to call.
‫We currently don't have a function that we want to call, so I'm going to go and create a new private
‫function over in my C++ header file.
‫And it is going to be a void function that is going to be called move forward.
‫And it's going to take the float, which is going to be the axis value.
‫Finish off with a semi-colon.
‫And I've got a little trick, a little extension here that helps me implement these things a little
‫bit quicker by doing control shift p and.
‫If I type in create implementation, it goes ahead and creates that implementation for me in the C++
‫file.
‫Really nice and easy.
‫The name of that extension.
‫If I go over, I always forget the names of my extensions, so I'll go and have a look for what it might
‫be.
‫Yes, it's this little doozy here, the C++ helper.
‫If you go ahead and install this one for your VTS code, it just allows you to do that sort of thing,
‫which is very nice.
‫Very handy.
‫So this is the function that we want to set it up to call.
‫So first of all, we say this, this is the target.
‫The current object is the target for this function.
‫Then we go ahead and put in the issue to the fully qualified function issue, to character, colon,
‫colon move forward and that should bind us to this function.
‫And then finally, what we want to do is pass that axis value on to the function that we actually want
‫to call, which is a parent function.
‫So we don't have to do anything.
‫We can just do ad movement.
‫Input like so.
‫So because this is the move forward method, we want to have the forward vector of the actor.
‫So the way we do that is we can do a get actor forward vector like so and then we want it to be forward
‫in the amount that our access value gives us so we can multiply by the axis value.
‫And that's going to give us the right result.
‫So we're going to have the forward vector multiplied by the axis value.
‫If it's one, we go forward, if it's minus one, a forward vector becomes a backwards vector and we
‫going backwards with just this one function.
‫So that's set us up with move forward.
‫Great.
‫The next thing is to bind for our look up.
‫So let's go and copy.
‫I always like to copy these string references so that I don't make a mistake.
‫Do a look up and instead of binding to move forward, let's go back to the head of file and create something
‫new.
‫It's going to be look up and again, a float axis value.
‫Like so.
‫And if I do control shift P and do create implementation goes ahead and saves me a little bit of time.
‫And this time instead of doing add movement inputs, we want to use one of those other functions that
‫we had at our disposal.
‫Namely the ad controller pitch input because we want to pitch up basically.
‫So this time we can do ad controller.
‫Pitch inputs and pass in directly the axis value.
‫Now.
‫Now be a bit more experienced C++ programmers among you might say, hey, this function basically does
‫nothing.
‫It is just calling some other function with the same parameter.
‫So it's not really doing very much.
‫And you would be right.
‫So what we could do is we could do the a shooter character look up so we could call the function that
‫was defined on this class the a shooter character.
‫Or we could say, well, there's add control pitch inputs that we could just call that directly, couldn't
‫we?
‫So if we use F12 to find out where that's defined and you go and navigate to it, you can see that it
‫is being defined in actually pawn h.
‫So if you scroll up, you can see all the way up here somewhere we're going to find a class.
‫Let's, we could even just search for class space, something like that.
‫And here we've got a pawn is the class.
‫So let's go back to the shooter character and what we can try and just make this a little bit shorter
‫by saying instead let's do a pawn colon, colon, add controller pitch input so that it automatically
‫just directly calls that parent function rather than having to go via our own function.
‫This is a valid way to do it as well, but it's just not necessary.
‫So I'm going to comment it out so that you can refer to it and see it if you wanted to do it that way.
‫But I would recommend doing it the slightly shorter route like so.
‫I and in trying to compile it, I noticed that instead of calling behind Axis, as I'd been wanting
‫to do, I've been doing bind action.
‫So you've probably been screaming at your screen the whole time.
‫Let's go ahead and build that again.
‫By the way, I'm doing that with a control shift B and selecting the build option.
‫That is the simple shooter editor win 64 development build, which is just a quicker way for me than
‫going over and hitting the compile button.
‫I'll look and I can't get my syntax right today.
‫Of course we need to use the ampersand in front of this function to say basically that we want to get
‫the pointer.
‫We want to use the ampersand in front of these functions to actually have the correct syntax here.
‫Okay.
‫So after I corrected those two very common errors, one being that I'd got the wrong function call and
‫the other being that I hadn't got an ampersand in front of the functions I'm trying to use.
‫Let's go over into Unreal and see whether this is actually working.
‫If I go ahead and hit play and use the W key and the S key, you can see I can move forward and backwards.
‫It's amazing.
‫And with the mouse I can look up and down, but it is feeling inverted at the moment to my movement.
‫So I'm just going to go over to the product settings and hit minus one in there and go ahead and hit
‫play.
‫And now if I go up and down, it feels correct.
‫Notice that I'm actually spawning in two different locations.
‫That's because I have to player starts when I put the second one in.
‫I didn't realize there was already one in the level, which is why I'm sometimes spawning here, sometimes
‫spawning in a different location.
‫You might find the same thing.
‫So it is challenge time.
‫Let's get you guys binding your movie rights and you'll look right so that we've got full control of
‫our movement.
‫So repeat the process that I've just done in the lecture for both of these two and you've probably been
‫following along.
‫If not, you can go in and watch to revise.
‫And also I'd like you to attempt the jump function as well.
‫If you're feeling brave, pause the video and have a go.
‫Okay.
‫Welcome back.
‫So let's give this a shot.
‫First of all, we're repeating the above steps for move forward and look up.
‫So we're going to be having move, right?
‫And we're going to be having instead of look up, we're going to be having look right.
‫And we can go ahead and copy these to set up our axes in the project settings.
‫So add another couple of axes mappings.
‫The first one is going to be move, right, which I'm going to map to the key, a four left.
‫So that's going to be the minus one.
‫A is going to be minus one because it's actually left the opposite of right and DX is going to be four
‫going right now.
‫Obviously, you can add in your arrow keys here as well.
‫I'm just not doing that to save time.
‫But you can go ahead and do the same thing.
‫You can just add more keys here, as many keys as you like to map to that single axis look.
‫Right.
‫We're going to use the mouse x.
‫And I think one should be sufficient rather than minus one.
‫I don't think we have to invert this one.
‫And then what we're going to do is we're going to bind this slightly differently.
‫So I'm going to go alt oh to go and create ourselves a move right function here.
‫Now you might be wondering, why are we doing this differently?
‫Why is move right?
‫Why are we not just calling straight to add movement input?
‫The difference is here we're doing a bit of calculation.
‫We're adding in this multiplication by a vector, which is adding a bit of information and justifying
‫the existence for this function.
‫So this time, instead of getting the act of forward, want to get the actor right vector like so and
‫multiply it by the axis value and then we want to be calling instead of move forward.
‫We want to be calling move right now for look.
‫Right.
‫Instead of adding the controller pitch input, we want to be doing the your input.
‫Remember roll pitch and you're from aeroplanes.
‫You can look it up on Wikipedia if you're not sure which one is which and go ahead and build that one.
‫Hopefully this time I haven't got the syntax wrong.
‫Let's dive over to the editor and hit play and there you go.
‫I can look all the way around me.
‫That's looking good.
‫I can strafe left and right.
‫I can go forward and backwards.
‫So the thing left for us is jump, which is going to be an action mapping rather than an axis, because
‫it's a discrete action and I call it jump and copy it.
‫Go over to Visual Studio code.
‫And just close down my compile window and here I'm going to instead of binding an axis, you've got
‫it.
‫I'm going to be binding a action bind action.
‫Simple as that.
‫It's going to start off still with the text here.
‫Of jump.
‫But the thing that is different with axes, as you probably remember.
‫Is we need to use this syntax I input event, which is an enum, which means that it basically can take
‫a number of these different options, double click, press release, etc. We're going to want to jump
‫on press like so, so.
‫So that's I underscore pressed and then once we know that we can go ahead and do the same this and then
‫we want to be calling to jump.
‫Now where is jump defined?
‫Is it in the --?
‫Let's have a look.
‫Nope, but it might be in the character.
‫So I'm going to do a control P and look for character.
‫Dot H.
‫Open that up and just have a look through here, see if they have a jump function defined in here.
‫Jump and then open brackets often is a good way to look for functions within the header files.
‫Sure enough, we have got that function.
‫You can see the documentation.
‫I often like to use the source code directly rather than looking up any documentation files.
‫I just find it sometimes a lot quicker to access, especially when you have access to control.
‫P In Visual Studio code.
‫So what we need to do is instead of going --, colon, colon, we need to do a character colon, colon.
‫So it is going to be ampersand, a character colon.
‫Colon This is because that's the class it's defined on.
‫We can't go looking up the hierarchy when we're doing this colon, colon operator and then it's just
‫going to be jump.
‫So character, colon, colon jump.
‫And don't forget that I need a semicolon on the end of the line.
‫Go ahead and build and see whether we're able to jump now.
‫Well, the build worked out correctly.
‫Let's go over to the sandbox level.
‫Hit play and try and jump.
‫I don't have any key bound, so that might hamper me.
‫Add the space bar in as the key that I want for jump and go ahead and hit play.
‫Yay.
‫I'm able to jump up and down and move through the air and move around.
‫Fantastic.
‫So we've learnt how to bind our axes and actions where we haven't learnt it.
‫We have revised it, but we've seen what we want to bind to in a character in order to get that classic
‫character jumping, strafing, moving and looking with your camera that we all know and love from our
‫shooters.
‫And the next lecture will look at the nuances required for moving with a controller, as well as a keyboard
‫and a mouse.