 Hello there everyone, welcome back to Gamedev Academy. I'm Shane, please let me know that you're in class by leaving a comment down in the doobly-doo just like these amazing individuals did in the last class. What I would like you to do as well is if you've joined us on Discord, please put in brackets which house you're in as well. So I would put for instance here sir in brackets Amano because I've been sorted into house Amano. If you do want to join us on Discord then use the link in the video you'll be put through the sorting quiz. It's a bit Harry Pottery and I will see you in that. In this class what we're going to be doing is taking the work we've done so far and turning it into more of a game. So the first thing we'll do is make it so that a ball will spawn when we want it to. So we're going to make it spawn at the paddle and then we'll make it so that until you fire the ball it will follow the paddle side to side so you can aim. That's what this step is going to be all about. It's very blueprint here we're getting into proper coding now so let's just do it shall we? Yeah okay let's do it. So what we want to do now is to get the ball to spawn when we spawn a new ball at the paddle wherever the paddle is. So we need to first set that up in the paddle blueprint. So I'll open that up the player paddle. Here she is and what I want to do is go into the viewport section of this and I want to add an arrow component. So here under add component if you scroll all the way down to the bottom you'll see that it's listed under utilities or you can just search for arrow and you won't won't really be able to see it but if I just move this out of here this is what the arrow looks like. Funnily enough it looks a lot like an arrow. So I'm just going to move it about 90 and I've moved it minus 90 you can see on why I've moved it minus 90 and that's because I already know which way mine's facing because I did test this before I did the video and then what I also want to do is rotate this. I'm going to start rotating it this way and I want it to be at an angle so just using this I can't get 45 degrees so I'm at minus 40 so I'm going to make that minus 45 and what that does is put this arrow component so that it's above my paddle or it will appear above the paddle in the game and it also means that when it launches the ball I can make it launch at a 45 degree angle because we can follow the direction of that arrow. What we need to do now though is check that that's worked so what I'm going to do is check in rendering visible yes but currently it's going to be hidden in game and when the game's finished we want it to be hidden but for now we need to be able to see it so I'm just going to deselect that I'm going to compile my blueprint and then we'll go to play and test it out and you can see that that has appeared exactly where we want it to. The problem though is that it's not yet following the paddle and we need that arrow to go with the paddle so that let's say we lose a ball and we want to spawn a new ball over here then the arrow needs to be there so we can spawn from there so we're not there yet. The way that we need to do this is we'll go back into this player paddle you can see here we've got the default scene root paddle arrow and what we can do is make the arrow if we just drag that onto there we can attach the arrow to the paddle so we'll do that and you'll see you get a little sort of dependency thing going on here and then we'll compile that again and we'll test and now when I move side to side you can see that the arrow is following the paddle which is going to be very very useful for us when we want to spawn balls. The next thing we want to get set up is give the the player paddle the ability to spawn a ball and we're going to go back into our blueprint for that and we need to be in the event graph here we are so I'm going to create a new custom event as I am fond of doing so right click custom event and I'm going to call this event new ball that seems like quite a descriptive name for this so when this is called I want to do a spawn actor from class there it is and so anytime this event runs it's going to spawn an actor which makes sense because we want it to spawn the ball so from this class here what we're going to do is tell it that we want the ball so there's BP underscore ball which is what I called my ball so that's now going to be the one that gets spawned whenever we call this and then what we need to do is you see we've got a spawn transform and that the information we can give that is where we want this ball to spawn which is going to be at the arrow so we need to set that up as well so what we're going to do is get a reference to the arrow so I'm going to drag this in and we're going to get it and then we need to get the position of that so we're going to drag out of the arrow I'm going to do a get world transform and then the return value is going to go into spawn transform so let's review what we've got going on here so whatever new ball is called it's going to spawn a ball there you go and it's going to spawn it at the position of the arrow which is exactly what we want so I'm just going to neaten this up a little bit let's just put all these things here get these two and I'm just going to bring those up a little bit I'm going to put this all in the comment which I'm going to call spawn ball good name and then we need to be able to test this out so I'm just going to create a new event which is begin play so whatever the game starts and we're going to do spawn ball no we didn't call it that we called it new ball didn't we new ball so at the beginning of the game it's going to spawn a ball and we're going to be able to test the center in it but it won't work yet because there's already a ball in there and the ball's launching as well all we want to do is get it to spawn at this stage so we need to disconnect a few things as well so we'll go into them let's just compile this we'll go into the level we'll delete the ball that's already there so we don't get confused lovely and then we're going to go into the ball blueprint for a second and somewhere yeah so on event begin play the ball is being launched we don't want that just yet so I'm just going to disconnect that by holding Altama keyboard and clicking on the wire that connects them that's disconnected that and I'll compile that so now let's test this and see if it's working it is so we've got a ball that's being spawned at the beginning of the game at the location of the arrow at the base of the arrow the next problem we've got is that before we launch it we want the ball to follow the paddle we want it to go with it so that's the next thing we're going to set up in this step so that's just stop testing right the next thing I want to do then is I'm going to go back into my player paddle here it is and what we can do is we're making this blueprint the paddle spawn the ball but they're different blueprints so what we can do is if we want to do anything with the ball from within the paddle it helps to have that as a variable that we can talk to so at the moment we know that this is the ball so the return value is basically the ball so what I'm going to do is just drag out of here and then from the options I've got one of the top ones here is promote to variable so then we get this so it's going to say once you've got the ball make it a variable and there you go you can see it's called new variable underscore zero we're going to change that to ball and then going forward within this blueprint we can do things with the ball which will be very helpful right so now what we'll do is we'll go into the ball blueprint I'm going to make it so that the ball once it's spawned will follow the paddle while ever the ball's not in play so what we're going to do is create a new custom event custom event I'm going to call that update position there we go and so we're going to use this event to be the thing that updates the ball we only want this to happen there when the ball's not in play so when it's not active so to control that we're going to create a boolean variable booleans can either be true or false so it's going to be is the ball active true yes it's active false no it's not so while ever it's false we can update the position so we're going to create a new variable click here and I'm going to call it active like that and by default let's just compile this by default you can see that that's set to false it's not active which is what we want for now and then we can control whether or not it's active by setting this variable to true or false once we launch the ball or when the ball is dead so we'll set that up later okay so what we're going to do now is get this set up so we'll get active and we're going to get it and what we want is that whenever this is not true so we're going to drag out of here and make a not boolean so if that's not active we're going to create a branch now a branch is basically just an if statement if it's true do this if it's false do this so we're going to in fact if you even type if you'll see that branch here branch comes up but I'm going to search for branch because that's what they're called in blueprints so we'll create a branch like so and so the first thing that this update position is going to do is check whether or not the ball is active in order to move forward it's not active which will be true and then we're going to get a set actor location there we go so this is going to set the actor location of the ball and we're going to relate that to the arrow but at the moment we don't have access to the arrow because that lives within the player paddle blueprint this one here not within the ball so we're going to do something called casting to another blueprint and we'll do this at the beginning of the game we'll ask this blueprint to talk to the player paddle blueprint and say I want access to something in your blueprint which is going to be the arrow so we'll set that up now so just up at the top here we've got this event begin play that's currently launching ball I'm just going to put some more stuff over here that's going to talk to the the player paddle blueprint this is still disconnected for now so just here I'm going to right click and do get player controller just here and then out of the return value we're going to do get controlled pawn which is our paddle and then out of here we're going to do cast to player paddle there it is so this is all tickety-boo and that's going to happen at begin place I'll just connect that up so as soon as this happens we're getting all this information from the player paddle and then as blueprint player paddle we're just going to promote this to a variable and we're going to call that variable player paddle so I know what it is let's get rid of that capital l don't need that so player paddle and that now at the beginning of the game we're going to have access to player paddle so that's one of the first things that the game's going to do when it starts up it's going to say to the player paddle can I have access to your blueprint and then we've got access to that within this blueprint going forward so that means we can now go back here and do stuff with that information so what we need is a player paddle reference so I'm going to drag that out here and we'll get that and what we want to do the thing that we're really interested in is the arrow so I'm going to drag out of here and type arrow and you see I can get the arrow so now I'm getting the position of the arrow which is good and from that we need to get the world location get world location because we need to know the position of the arrow that's why we're interested in it and then the return value of this this get world location information that we've got we're going to put into the new location so where we want the ball to be put so the target is self do it to the ball because we're working in the ball blueprint and then if the ball is not in play get the world location of the arrow and put the ball there so that should make it follow it but we need to then have something to trigger this updated position to make it work so somewhere in here I think we already have event tick we do so you can see every tick is currently updating the velocity and angle of the ball what I want it to do as well in fact let's just um so that's just doing speed and angle so we're going to have to do a little bit of reorganizing here and we also want it to do every tick update position there she is and I'll put that in a comment just so I can see what I'm doing update position of ball just so I know what's happening there okay so every tick that's going to happen and then what I would like to do is just neat and all this nonsense up a little bit and then we'll put that in a comment as well update update can't spell ah update ball position when a little bit french there okay so that should work so at this stage we're going to compile and test now I know this isn't going to work so I'm making myself look stupid on purpose here um because there's one other thing we need to update but I want to show you the problem before we fix it so we're just going to compile that and then we'll test and the idea now is that the ball should follow the paddle but it isn't doing and that's because we need to make one change so if we're going to that BP ball it's because the ball isn't the root so it's happening to self which is the whole blueprint but the ball is kind of contained within the blueprint it isn't like the focus of the blueprint to fix that we're going to drag the ball here on top of the default scene root and then the ball becomes the default scene rule so we'll compile and save that again and then play it and we're getting somewhere now so what that means is that when a new ball spawns it will spawn where we want it to which is going to be just above the paddle and we can take aim before we launch it so we can move left and right and so if let's say we're just aiming for that last tricky block we can put the the paddle over here and then we can fire obviously we've not implemented a launch ball yet so we can't do anything with it but we're getting there in the next step what we will be doing is getting itself to launch the ball so that we've actually got a game that we can play so i hope to see your beautiful ass in that next step see you later 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