‫Hello.
‫Welcome.
‫In this lecture, we're going to be adding in controller movement so that we can move around using a
‫controller, which is what you're seeing going on right here.
‫I'm going to do this using a different set of axes for look up rate and look right rate, and we'll
‫see why that is necessary.
‫Let's dive in and find out why.
‫So I want to be able to move around our scene using the controller.
‫I can already do this when I am not in play mode.
‫So we want to be able to do the same sort of movement as this with panning with the right stick and
‫with moving around left and right with our left stick.
‫And we can also go up and down.
‫But that's not something that our opponent is going to be able to do, because it's not a flying pawn.
‫So what we're going to want to do is, first of all, it's easy to map the movement.
‫All we have to do is go to our project settings, go down to wherever input is, engine input, and
‫we've got our move forward axis and we've also got our move right axis.
‫And that's pretty straightforward to add in yet another mapping as well as W and S, we can add in our
‫gamepad.
‫If we look under gamepad, you can see the left thumbstick we want the y axis for moving forward.
‫For the moving right, we're going to add the again the gamepad and it's the gamepad, still the left
‫stick.
‫But this time we're doing x and y axis and we can see whether that is the right sort of movement.
‫So go ahead and hit play.
‫I use alt p as my shortcut for that.
‫Then left and right works forward and backwards works as we would expect.
‫But obviously turning doesn't work because we haven't mapped that yet.
‫So let's give that a shot.
‫If we go to settings, project settings and input again, let's have a look, look up.
‫We currently using the mouse y.
‫What would be wrong with just adding in here?
‫For example, the gamepad, the right stick, and this time the y axis?
‫Well, on first attempt we can go and have a little play.
‫This might actually seem to be okay.
‫So we go in and you can see we can move around.
‫Yeah, sure.
‫It's a little bit fast, but it's kind of okay, isn't it?
‫Isn't that okay?
‫Well, not really.
‫And the reason ultimately boils down to frame rates and how these axes work.
‫So what happens with a mouse when we're running a game at 30 frames per second, when we move our mouse
‫from left to right across the screen at a kind of even speed, we might see that the axes values are
‫something like ten, then ten, then ten.
‫And this is telling us that each time the mouse has moved by ten units to the right and it's done it
‫the same every frame.
‫What happens if we double our frame rate?
‫Well, suddenly the mouse is still moving at the same rate because the player is still moving their
‫hand at the same speed.
‫But because we're showing frames more often, we're having ticks more often, then what's going to happen
‫is the input from the axes is actually going to be halved each time we're going to get a five of five
‫or five of five or five.
‫So great, that's fine, because that means that we're still going to be panning across our screen at
‫the same rate, no matter whether we have a fast computer or a slow computer.
‫If we move our mouse by a certain amount, you're going to notice the same amount of movement, which
‫is what we want.
‫Now things change a little bit when we look at the controller, say we go full throttle to the right
‫with our analog controller and it's at 30 frames a second.
‫We get one, then one, then one.
‫Makes sense, right?
‫What about if it's at 60 frames per second?
‫We still get one, then one, then one, then one.
‫But we get more of them because we're getting more frames.
‫If you use that directly to affect the movement of your pawn, you're going to see that it moves at
‫twice the speed, at twice the frame rate, not what we want.
‫So what we want to do is introduce some frame rate independence here.
‫So to do this, we need to be able to multiply by the delta time.
‫We kind of want to use the input axis to help us modulate the rotation speed.
‫So that's a little bit to take in there.
‫But what I mean is that we need to have something like a rotation rate variable.
‫We're going to create a new property for that, which is going to be an edit anywhere and we are going
‫to have it be a float and it's going to be the rotation rate.
‫Now I'm going to use the same rotation rate for both up and left and right.
‫You can go ahead and have a separate variable for both of those.
‫And I don't really know what a good rotation rate is going to be here.
‫I'm just going to give a flying gas hex.
‫I'm not sure what the units involved are here at all, so I'm just going to go ahead and say ten.
‫But we'll see.
‫Maybe that's way too fast.
‫Maybe that's way too slow.
‫We can adjust that in our blueprint so we can go ahead and save that.
‫I'm going to go over to the C++ Alt O to switch the C++, by the way, and we're going to want to have
‫a new type of axis so that we can distinguish between the move.
‫Right, which is the mouse, a direct movement versus the move.
‫Right?
‫Or rather sorry, the look.
‫Right, which is the rate.
‫So we're going to do that by going over to our project settings and instead of having this gamepad left
‫thumbstick mapped to the move.
‫Right, sorry, not the left thumbstick, but the right one mapped to look up.
‫I keep making that mistake, remove that from that axis and add a new axis which is going to be the
‫look.
‫Up.
‫Right.
‫And this is going to take in our gamepad, right?
‫So a gamepad, right.
‫Y axis because it's a look up and we're saying that positive one should be the one that we're using.
‫So then what we can do is we need to map this and we don't want to map it directly to the ad controller.
‫Your because we need to do a little bit of maths to calculate the rates and make those rates frame rate
‫independent.
‫So what we're going to do is go over to alt zero and create ourselves a look up, which handily we've
‫already got here.
‫And I'm going to create it as look up right and go ahead and create this control shift.
‫P And I'm using my implementation plug in.
‫Let's go ahead and do a look up rate implementation.
‫Got an axis value coming in.
‫That's great.
‫We then want to make sure that's what we're calling in set up player input component.
‫So let's create a new line here, duplicate the look.
‫Right, I'm going to call it look up.
‫Right, like so and then copy and paste the.
‫Fully qualified reference to the function to call our look up rate.
‫Then essentially what we want to be calling at the end of the day is add controller input, pitch,
‫controller, pitch input.
‫But we want to multiply this by a couple of things.
‫So our access value comes in as a value between zero and one.
‫If we multiply that so axis value multiplied by the rate rotation rate.
‫Then what we're going to get is a speed, but what we want is actually a distance.
‫Like when we moved our mouse, we moved at a certain distance, every frame.
‫That's what was coming in.
‫We want to convert this speed to distance.
‫And if you remember some way back in, some hazy math class, to get from speed to distance, we need
‫to multiply by the amount of time.
‫So we do that by getting our Delta seconds from the world.
‫Now what is Delta seconds?
‫That is the amount of time that it took for the last frame.
‫So it's kind of the opposite of the frame rate.
‫It's telling us how long a frame takes, which is great because that is the amount of time that we need
‫to apply this movement over.
‫So if you think about it, we've got a speed, we've got an amount of time that we need to apply that
‫speed over.
‫It gives us an amount of movement that we essentially want to apply to our controller pitch input.
‫So that's what we want.
‫Get World first of all, because we want to get the level, we'll get the world around us.
‫And then from that we use the arrow function to do get Delta seconds, which tells us that we want to
‫get the amount of time that elapsed in the last frame, which gives us again this approximation of our
‫frame rate at the current moment in time.
‫Now you might be wondering why we're not doing the same with the movement input, and the reason is
‫that the movement input, when you do an ad input there, it's already supposing that that's a rate,
‫not an actual amount of movement.
‫So it's already doing this calculation for us, essentially under the hood, save up the files, go
‫over into unreal and compile and see whether any of this is worth it.
‫So let's head on into play and I'm going to try and use my controller input.
‫There we go.
‫We're going up and down rather slowly.
‫But hopefully this will be completely frame rate independent because we've used that delta time.
‫So what I want you to do is to go ahead and implement the look right rate.
‫So repeat the same method set up for looking right as he did for looking up and tweak the speed so that
‫it doesn't go really slow and you can actually use it to move around the level, pause the video and
‫have a go.
‫Okay.
‫Welcome back.
‫So first step was we went and created a new axis mapping in our project settings.
‫We're going to have to do that again, this time for the look.
‫Right?
‫Right.
‫Like so what a mouthful.
‫Then we're going to go and get the gamepad.
‫The right this time and the x axis, that's the one we're going to be mapping.
‫And then we're going to go over to our shooter header file this time.
‫We're going to duplicate the look up rate.
‫And let me just show you the files so you can see where I am over on the left hand side.
‫So we're going to have instead of the look up rate, it's going to be the look right rate control shift
‫p create implementation and we're going to have pretty much exactly the same code with the same multiplication
‫that is getting us from, again, a speed to a amount of distance moved.
‫That's the look.
‫Right, right.
‫So instead of doing the add controller pitch, we need to do the your input this time and the look right
‫rate is going to need to be called from our set player input component or it needs to be called when
‫the axis is actually being manipulated.
‫So we're going to add another axis in here instead of look up rate.
‫It's going to be the look right rate.
‫And then so we're going to want to copy that reference to the function, remembering the ampersand before
‫and then the fully qualified issue to character.
‫Colon.
‫Colon, look right rate.
‫Let's go ahead and save both that and the head of file.
‫Go back into the project and exit play which I left going hit compile here and then.
‫We should be able to dive in and have a play around.
‫So.
‫Up and down is working slowly, left and right.
‫Not quite working out how I would expect.
‫Let's check our project settings.
‫So our look.
‫Right.
‫Seems okay.
‫Thumbstick right.
‫Thumbstick x axis.
‫Let's check that.
‫That's all going through into the C++ correctly bind axis look.
‫Right, right.
‫It's calling look right rate function or seams in order calling the your input as it should be.
‫Dana, what happened there?
‫I just hit recompile again and then hit play again.
‫Sometimes you have to do this.
‫But now the looking left and right is working up and down is working, albeit at a very, very slow
‫pace.
‫So we're going to tweak around with our character blueprint.
‫Let's go and find our VP shooter character.
‫Open up his blueprint.
‫And then let's scroll on down and find the rotation rate, which I'm going to just multiply by ten.
‫Try and go ten times faster, then we'll find a value that makes sense somewhere in between.
‫This is always one way that you can try and find values is just by going and changing the order of magnitude
‫first.
‫Well, that's much more closely in the right ballpark.
‫It's maybe a little too sensitive, so maybe I just slam that down by a half.
‫Try about 50 this time.
‫Not 500, but 50.
‫Let's try that out.
‫Hit play and move my stick around.
‫That's feeling much more natural.
‫You might want to go somewhere just a little bit in between those two.
‫So go in between the two.
‫Again, I'll say about 70 this time, rather than going all the way to 170 might be the right rate.
‫Let's see if we've hit gold.
‫Yes, I think so.
‫I think 70 is going to be the right rate for me to move around.
‫Obviously, this is the kind of thing that often games allow you to tweak or allow the player to tweak
‫in the settings.
‫We're not going to look into that.
‫That's beyond the scope of this section, but it is something that you might potentially want to expose
‫to users in your own games.
‫Cool.
‫So in that lecture we have seen the difference between controller input and mouse input and how we have
‫to deal with rates instead of absolute movements.
‫So in the next lecture, we're going to look at that third person camera that I kept hinting at.
‫See you there.