 Hello there class! Welcome back to Game Dev Academy. I'm Professor Whittington and it's time for another game development class. Make sure that you sign the register in the doobly-doo, just like these stunning people did in the last class. In this class, we're going to be looking at doing actual scripting. So we've done like a mock-up and now it's time to actually get the paddle working, moving side to side, and jumping to blueprint improperly. So without any further waffle from me, let's just jump into it. Okay, here we go. So let's start turning this into an actual game. And the first thing we need to do is get the paddle working, so we need to get it moving left to right, so it can hit the ball into the play field. And what we're going to do is create a pawn for that, which is a type of blueprint, and that's going to act as our player. That's the thing that the player will control. So we have a blueprints folder, which is where the game mode is. So let's open that up. I'm going to create a new blueprint in that folder. So I'll right-click in there. I'm going to open blueprint class. And the one that I want is a pawn for this particular part. So I'm going to call it player paddle, like so. And then we need to open this up. I'll just dock it alongside my level there. Now that's open, what I also want to do is go into the game mode and make it so that the game mode realizes this is the player we want to use. So let's just go here and open the game mode quickly and just make sure this is saved first. And then here I'm looking for the default pawn class and it's currently set to default pawn, but we want this to be our player paddle pawn instead. And that's all we need to change there, just so that when we start the game, it knows what we want it to use. So we'll compile that, save it and close it for now. So back to our player paddle, what we need to do now is get the paddle in here. So this little sphere here is just like a null actor. It represents a default scene root, I believe. So it actually doesn't do anything and we won't see it in game. So we can ignore it. What we want to do, though, is put the paddle in. So we're going to go up here to add component and we'll just give it a click. And what we want is a static mesh. There it is. So I started searching for a static mesh popped up and what that will do is put our static mesh here. So I'm just going to call it paddle for now. And then we actually need to tell this static mesh component that we want it to be the paddle. So over here in our details panel is where it's asking us what static mesh we want to use. So from our list of measures we've imported so far, we can choose paddle and that will just drop in there. That's pretty good so far. Then there are a few things that we need to do to the static mesh, to the paddle, to make sure that it works. So the ball bouncing around is going to be based on physics, the physics system in Unreal Engine. So we need to make sure that this is set to simulate physics. So in the details here, if we go not too far down, there's a physics section and I'm just going to tick the box. Yes, I would like this to simulate physics so that when something hits it, it's likely to bounce off. What I also need to do, which is very important, is make sure that this doesn't respond to gravity because we want this to be kind of hovering in midair. If we turn gravity on, it'll just fall. So we're going to disable this thing here for disabled gravity. We'll disable it. So I take the tick out of the box, so far so good. And the last thing I want to do is just increase what's called linear damping. And what that does is kind of acts against if when we start it moving, that stops it moving too freely and that's something we'll need to get the paddle to stop again. So I'm just going to set that to 20 for now. That's a nice number. And then there's one final thing that I want to do to make sure that we don't get any unexpected movement out of the paddle and that's to lock some of the constraints. So we only want it to move side to side, which in this case is the x-axis. And we don't want it to rotate at all. So we're going to lock everything that isn't just moving on the x-axis. So here we've got a constraint section. So we're going to lock position on the y and z axes. And we're going to lock rotation on x, y and z. So it won't do anything we don't want it to. And that'll do it in here for now. So I'm just going to compile this blueprint and save it. Now it's time to do some actual scripting. So whenever you're doing some scripting on a blueprint in Unreal Engine, each blueprint has got its own event graph, which is where the scripting happens. So we'll open that and you'll see there are three nodes there ready for you. So we can have it do something as soon as the game begins or when it overlaps with something or every tick, which is kind of every frame, every CPU cycle. But that's actually not what we want in this case. So I'm just going to delete all three of those so we can put in just what we want. I don't want this to be any messier than it needs to be. And we're referencing the horizontal movement, which we created in the input section earlier. So if we just start typing input axis, so then it brings up this axis events and there's the horizontal movement that we created earlier. So that's what we're going to do. And what will come out of this is an axis value, which can be anywhere between minus one and one, which is what, again, what we set in the inputs earlier. So we need to be aware of that because we're going to have to do some multiplication with it. I'm going to use that to add an impulse to the paddle. So we need to add an impulse node. So I'm going to right click again and I want to search for add impulse. And you'll see that this comes up and it also puts in brackets paddle. So I know what I'll actually be adding this impulse to. So I'm just going to put these either side of my screen. I'm just going to move the paddle down. I'm going to try and keep this as neat as possible because these can get like really it's like messing with spaghetti when it gets complicated, which we don't want. So we've got an impulse there and that's what's going to add to the paddle. And what we need to do to get something to move in a direction that's known as a vector. So out of here, the axis value, we need to make that become a vector. So I'm just going to drag out of here and search for make vector. If I can spell it, there it is. And that will return a value. And that's currently just happening on X, which is what we wanted to be doing. And then what that will do is it's going to put a value. So let's say we press the right key. That's going to make X a value of one because it's coming from the axis value. And that's going to be something that will be returned here. But that's not actually going to be strong enough. If it's just moving one, it's hardly going to move this at all. We're going to need much bigger numbers. So for that reason, I'm going to need to multiply this value here. By something else. So that's something else is going to be what's called a variable. And that's something that we can set a number in and we can do different things with it. Have it change in the blueprint during game, which is really good. So we're going to use what's called a float variable, which is just a number, but it's a number that can have decimal places after it, as opposed to an integer that can only be one number. So one, two, three, not one point, four, eight, seven, whatever. So I'm going to add a new variable just here. I'm going to call it speed, since that's what it's going to control. And by default, he's got this red icon here, which means it's a Boolean, which means it can either be true or false, which is no good. So I'm just going to change it here to a float. And what I want to be able to do is to set its value here in default value. But at the moment, there's no inputs there for me to do that. And that's because we haven't yet compiled it. So it doesn't exist yet until we compile. So let's compile it. And you can see now the speed appears. And I'm just going to set this to a default value of 500 to get us going. So that means that when I put this into my blueprint, so we'll just drag this from here. And we've got the option to get it or set it. The moment we're just getting the speed, so let's get that. And we need to multiply it by this. So what I'm going to do is just drag out of here and I'm going to do float. And the one I want is this one here, which is float times float. It's multiplication. So let's put that there and we'll just get the result going into X there. And we're going to multiply it. So we're going to get one or minus one going into here. And I'm going to multiply that by speed, which will be 500. So what will come out of here will be either 500 or minus 500 since the only options we've got at the moment is that a key is pressed or not pressed. So it can well, it can be it can be 500 minus 500 or zero when a key isn't pressed. So we get that and then the return value for this is going to go into the impulse here like that. So this is nearly done, but actually this impulse here is never going to be triggered because it's got nothing coming into it here. It's not going to execute. So what we need to do is connect that from here. So this is when we get something on that horizontal input. So when that happens, do this. So it's going to go through there and it's going to execute that. So adding an impulse to it. So it's adding an impulse to the panel. They can see there's a target and the impulse is coming from here. Get the axis value, multiply it by 500 and put that into the impulse. And that's everything that we need to do for that. So what I'm going to do is I'm going to comment this. So I'll select it all, press C and I'm going to call that paddle like so so that later I'll know what this is. So at this stage, it's time to compile this and we'll save it. And now we need to know whether or not this is working. And we'll only know that through testing. So it's time to go back to our level and we can see that we currently have a paddle in place. But all this is really is a dummy paddle. This won't do anything. So what we can do is delete that for now. And what you might be tempted to do is to import this blueprint like that. That actually won't work for what we're doing for the method we're using. We've got to put in what's called a player start. And that is that tells the game when it runs to spawn your default actor at that place, which will be our paddle. So we're just going to get a player start. No, that says play to start. Oh, Shane. So player start. I'm just going to throw it in anywhere. And then I'm going to set it to zero, zero, zero, like so. So that should be in the right place. So what we need to do now is just click on play to test this and see whether or not it works. So I've clicked on play. The good news is that a paddle has appeared. So I'm going to click in my viewport window and then I'm going to press the arrow keys left and right. And we can see it is moving very slowly. This would not be a fun game to play. So we're going to have to go back into the blueprint and make some tweaks to get this to run properly. So my advice to you is to get hold of your speed variable and make this number bigger until you're happy with it. So I already know that I like a value of twenty five thousand, but you might want it to go faster or slower than that. So make sure you put your own value into something that you feel happy with. So I'll compile that and then we'll test again and see how that feels. So that's much snappier. It's also hitting the edge of the level so that I can't get out of that. So that's all working pretty nicely. So now we've got our input set up. It's also working on A and D when I press those. That's pretty good. So if you do want to make your own little changes to this, the three things that are worth changing are let's go to the paddle. It's worth playing with the mass. It's kind of the default mass at the moment, but you can make it lighter or heavier and see what effect you get. You can also change the linear damping, which is how much kind of external force act on that paddle to slow it down and stop it after you've stopped pressing your button. And it's also worth changing the speed as well. Just any combination of those three things will give different results. You just get something you're happy with so that it feels kind of fun or at least not horrible to move that paddle side to side. So that's pretty much it for this step. Well done for sticking with it. We're now getting into proper scripting and stuff. It's very exciting. In the next one, we'll be doing a bit more setting up and scripting and we'll create a blueprint for the ball and get some logic working on that. So I'll see you in that one. Bye. I believe that quality education should be available to everybody. And for that reason, all of the classes at Game Dev Academy are completely free and we're supported by our very generous school governors over at Patreon. If you'd like to become a Game Dev Academy governor and support our work, as well as helping us to steer the channel in the right direction, then use the link in the description to be taken to the Patreon page.