Create Your Own "Twin Stick Shooter" Mini Game | Unreal Engine Beginner Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] all right everybody welcome back to another Asad Dev Unreal Engine tutorial my name's Kevin We are continuing our mini games series and today we are going to be making a twin stick shooter start to finish now when I talk about twin stick Shooters I'm talking about the classic twin stick shooter things like Bing of Isaac enter the gungeon Geometry Wars next Machina Colt Canyon sleep tight take your P there's so many great examples out of them some of them get into bullet Hill some bullet hell some of them get into a building even there's even flying versions of it but the overall point is uh that's kind of the goal for today now there's some particularly interesting things about the twin stick shooter uh specifically in the sense that when I first started in unreal there used to be a tutorial called twin6 shooter it was great it was start to finish tutorial and it helped me really wrap my head around all the pieces and bits of creating a game in unreal that's kind of the point of these miniseries this one we're going to be taking a step back a little bit and even starting even more basic and trying to cover all of the various aspects of it with our classic um success condition so what do we need to build today we need to we're going to create a game we need to have a hero character and we need to be able to win the game seems basic our hero character in order to win the game needs to be able to shoot and CLE clear enemies so we need enemies we also need to have a level and we also need to be able to clear the level we need a little bit of UI to let us know how we're doing and with that that also means we're going to be building projectiles we're going to be building some very basic visual effects and all of this in Unreal Engine 5.4 so we have an insane amount to do let's go all right so starting off we are going to start off a little bit differently than we do most of our tutorials and we are actually going to start with the top de tutorial and this is going to just be our base project and I'm going to call this twin stick mini okay now even though we're starting with a template project we are going to go on a quick tour of all of the pieces so you are familiar with how everything works where everything is so that you can follow along and unreal so first things first before we even get into that let's make a couple project changes uh first thing is down here in the bottom left is the content drawer I like to dock this in the layout now what is the content drawer the content drawer is basically where all of your game assets live and when I talk about those I'm talking about your characters your levels uh everything that goes into your game gets organized into this content drawer that's where we find what we're looking for generally speaking the way the template projects are set up is you have your content your characters cursors fortunately all this stuff is named and then you have your top down in in your top down section we have blueprints we have inputs we have Maps so let's talk a little bit about that so blueprints these are the things that uh we are able to use to create basically various aspects of our game it works like a blueprint if I create a blueprint to build an enemy it's all of the information that the system needs in order for the enemy to work for example now same thing with our Maps this is where all of our maps are stored currently right now we have a top down map this is the world that our character is going to run around it now before we get into making some changes and some more on the tour I do want to make some project changes so underneath our editor preferences I come from a Maya background so I need to flip the middle Mouse button so uh you are going to find what works best for you and I believe for me I need to in this let me just double check yes this is exactly how I like it the other change that I like to make also from a uh just again coming from another 3D package standpoint is I like to enable the rotate I like to enable The Arc ball and the screen rotate uh just in case we're manipulating stuff as I as we go into other preferences Etc I will let you know what those are now generally speaking when we open a template project one of the cool things is it it works right right out of the gate so let's just go ahead and see what happens when we play our game right now and in order to play our game there's a giant play button up here in the top if we press play you'll notice that our character is spawned now this game is top down it works a little bit differently than others wherever I click that's where my character goes to if I hold and click the character basically follows my mouse the reason we picked this particular template is because the camera angle and everything is already very similar to a typical uh twin stick shooter camera so let's talk a little bit about how it is that this character is able to run around so in our level if we take a look at everything that's here once again a lot of this stuff is labeled very nicely for us I'm over here on the right this is our outliner this is our world outliner this is everything that makes up our world if we take a look at this we have a bunch of pillars fortunately they're labeled if we hide the pillars you'll see they all disappear so you can see which aspect of the game these pillars are same thing for these blocks if we turn off the blocks there you go we have navigation this is um this is basically everything that goes into the nav navigation is how our character moves around where they can go where they can walk along and a lot of this is built especially for enemies and then one of the things that I want you to key on right here is a player start we use this player start to determine where our character is going to begin when we press play so look at where this player start is when I press play I'll be right between these blocks and the pillars so here we are right between the blocks and the pillars if we want to move our player start we can just grab it using these this is uh Gizmo this Gizmo I'm moving this in X if I go ahead and start now I'm going to start much further back closer to this wall as an example okay so now what happens when we press play well when we press play Unreal Engine basically goes through a whole series of things loading the level loading the characters and everything that happens it looks at the player start and says do I need do I have a player in this case we do and if so I am going to start my player in this position now when we start our player what actually happen happens is Unreal Engine goes and it looks and says what is my default player for this particular game experience and in this case it is this blueprint for a top down character which is in our blueprint folder let's open that up and take a look at a couple things in here all right so our top down character blueprint has a couple of Key Parts to it and one of the reasons I'm showing you this is because we are going to be making edits in here now now from the standpoint of potentially previous examples you've looked at Etc there's actually not a lot going on in the event graph here and that is because a lot of that is in the player controller which I'll get to in a second the the top down character is basically the pawn it's the thing that is controlled it does all the visuals for our character in this particular case if we look over here in the components we have a mesh this is our character's geomet R the skin everything that is basically the visual display you can even see here the character in The viewport is actually breathing because it's in idle mode all right we have this spring arm this spring arm is our camera this is where our camera is going to be relative to our character when our spawn so when Unreal Engine starts our level it starts the player start it takes the camera and it aligns it to this camera location that we have set here for this particular character we have a character movement component this is what allows us to move uh there's a whole bunch of logic and things like that that allow us to at what speed can we walk can we run can we swim there's all kinds of stuff in here uh the scale of gravity all those things we're not going to get lost in that right now and then there's our capsule the capsule is very important when we move our character around what we are moving is we are moving the capsule and the visual of our character is just along for the ride so as we press play and we start walking around with our Mouse what's actually happening is if I shoke let me see if I can show collisions and show you all okay what's actually happening is our our capsule you can kind of see here maybe if I you can kind of see the let me eject here and zoom in okay you can see this capsule around our character if I turn off the visual for this character by simply resetting the let's see here our mesh okay over here I'm going to clear this mesh when I clear this you'll see my capsule is empty there's no visual for our character if we come back in here I'm going to move my player start back out in the middle just so I'm not by that wall when I press play this time you'll notice that I don't see my character anymore but if we turn on the Visions again you'll notice my capsules here so as you look you can see this capsule it's very hard because of the coloring of it you can see this capsule is actually still moving around in the level so actually what we're moving and the first level of collisions and everything that's happening is all being done with this capsule for efficiency for speed for performance so that when you play you're getting uh you don't get hitches and things like that all right let's let go back and add our our visual backend so back here in our top down character underneath the skeletal mesh this is what is going to be displayed I'm going to choose the Manny again and we'll just go ahead and do that okay so we are back to where we were where we have our character able to move around now how is this move happening when we click our Mouse I talked about the controller you'll notice right next to my top down character there here is this top down controller if we open this up interestingly enough the controller is what determines are you using a mouse are you using a game pad how are you doing that so one thing to note and I'm going to gloss over this really quickly is we have this mapping context what this is is this is our input mapping uh our input mapping context what it does is it determines which keys are going to allow our character to move what mouse clicks do what if we take a look at it just as an example when I open this input mapping context it's very easy to read here's all of our mappings we have a two of them only and we're going to be working in this which is why I'm showing you this we have a set destination click and a set destination touch what this does is it sets it up so that the controller can do something whenever we do a destination click so what happens in here if you're new to blueprints destination click gets called This is VIs visual scripting 101 stuff this gets called and it goes through these execution pens and it does its thing so in this particular case on click what it does is it finds the cursor location and if it is if there is an actual valid location it goes ahead and it follows the cursor now there's two of these one of these four and they're very well commented so on released if the input wasn't held try to move to the to the location under the cursor and this is if the input wasn't held try to get to location under the finger now we're going to be changing all this okay let's see what else we need to cover in our tour we talked about the controller we talked about our uh we talked about our a pawn it's called or our our top down character now now that we know where everything is and how it works what we want to do is we want to be able to change this to work in a twin stick shooter manner so the entire next section is going to be all about basically deleting a bunch of this stuffff and changing our controls so that we can use our gam pad so with that let's get a little bit into how are we going to update the controls for the twin stick shooter okay so to update the controls here's what we need to do right now this is based on where I click I don't want the click to happen that's not that's not what I want what I want is I want to either be able to use wasdi or the gamep pad thumbstick to move my character so I don't want it to automatically go wherever I click but I do want the Mouse stuff so that I can use that to update my aiming so let's start disconnecting and reconnecting a bunch of stuff I'm going to go into the controller and what I'm going to do is I'm going to basically disconnect all of this stuff and I could probably leave this here here's what we'll do actually here's what we're going to do we're going to delete this from the mapping context okay I'm going to save this mapping context and what that means is the game no longer knows what to do when I left click or right click but I'm keeping this in here as reference because there's actually some cool information in here that we can use when we build out our stuff so if we Press Play I have no way to move my character I'm clicking I'm Wasing nothing's working so let's go ahead and let's go ahead and add in some WD controls so to do that what we need we've talked about the mapping context that's what you're actually clicking on but we do need another thing called an input action so over here we have a uh basically these input actions are the they're the placeholder for what you want to do move jump attack shoot uh in this case set destination click Etc so what I want to do is I want to create a new input action and this input action we are going to call I a move and we're not going to do a whole lot with it we'll just go ahead and keep this as our defaults and then we're going to add this to our mapping context here so what this does is it makes it so that we have an input action called move and we need to bind it to a key so in order to bind it to a key I can click here and I can Cho something from the key from the list or I can just tap on this keyboard icon and click a button so let's just start simple let's just get our character to move forward so I'm going to press the W key so now my my character or the input mapping knows how to at least recognize when I press the W key so now we just need to tell our character to do something with that so let's go to our controller and if we rightclick in here and we type in move or actually let's just do I a move you'll notice that after we've added that we now have our input action for the en enhanced input system for move and when this is trigger all we need to do is tell our character to move forward all right let's do that so what we're going to do is we are going to have a left to right and a front to back much like if you ever looked at the third person setups it's almost it's exactly almost exactly the same like that so let's do a um Let's do an add movement input add oh actually we need to grab a reference to our controlled Pawn so let's get a self we could probably move all this into our our Pawn but so let's let's talk about this a little bit right now we're in the character controller so when I get a reference to self what it means is the character controller this is a reference to the blueprint that I'm in so with this what I'm basically saying is for this character controller I want to get the control P now what this is going to do is it's going to get this top- down character for that top down character what I want to do is I want to add in add a movement input so we're keeping this basic so when we trigger this we're going to go ahead and add a movement input now the direction that we're going to go is going to be determined by the control rotation so let's just get the forward vector and let's split this pen and let's get our control rotation and I'm going to split this pen and the reason I'm splitting this is because I don't want roll I don't want pitch I only want the yaw because we're doing a top down so think about it as which way I'm facing this way like if I'm in a swivel chair I want to know which way I'm swiveling I don't want to know which way I'm rocking or which way I'm pitching unfortunately they're called roll pitch and ya so we're going to grab this we're going to take this and we are going to connect it into our world Direction now if we don't give it a scale it is just going to always move forward at the same speed let's see what happens when we run this right now okay so if I press W our character moves forward if I press S A or D character does not move in any other direction right now because we have not mapped those keys so let's let's add a couple of little bits to our input mkin so here we go we have our W that's great we don't have any modifi on this right now and with that we're we're definitely going to be talking about modifiers as well so let me just double check do I want yeah okay so when we get uh when we actually make this work for the game pad we'll we'll add a couple changes for now let's just get WD working all right so we need another mapping this is going to be the S key so I'm going to click on here and going press s now we do want to modifier on this one and the modifier I want is I want to negate why do I want to negate if W's for s needs to be backwards which is the Opposites of forward so in this particular case now I have a front and a and a back and if we take a look at our move or our our top down controller it is going to take whatever the action value is and plug it in we need to plug this into our scale this is where we run into our first change that we need to make right now our move is basically a digital Boolean either it's happening or it's not that's not really what we want what we actually we want is we want this to be a 2d Vector the reason we want it to be a 2d Vector is because we if you think about a thumb pad on your game controller for example let's see if I can get this up here when you think about your thumb thumb stick you're pressing forward backwards that's one vector because a vector can go forward or backward left and right that's the second Vector so this is a 2d Vector we're going to be using with our with our game pad okay so now we have a 2d Vector if I save this when we come back to our top down controller if I refresh this uh Actually I don't even have to refresh it it just did it it gives me an action value and I can take this action value and I can split this and by splitting it you'll notice I get an X and A Y in this particular case I'm going to take the Y value and I'm going to connect it into the scale of my move now what this is going to do is if I am pressing W which is forwards it is going going to give me let's just say keep it simple it is going to give me a positive one okay if I press in y if I press the S key it's going to give me a negative one so it's effectively going to scale this so now that we have our scales connected we should be able to go forward and backwards but we can't let's figure out what happened there we have our scale our y value oh maybe oh we didn't let's just check to see if it's actually we have our axes messed up right now yep okay so right now X is connected so we probably want to flip this and to flip this so that it makes sense logically what we're going to do is in our modifiers we are going to over here let's take this and add in a modifier and this modifier is a little bit tricky it's basically Swizzle I don't I don't know why they went with swizzle instead of swap or switch or whatever but now that we've swizzled that let's go ahead and actually we may need to move the Swizzle up one more hold on a second let me just double check yeah we basically need to Swizzle both of these okay so in addition to the negate we need to Swizzle so let's Swizzle this so this is basically switching our X and our y values so the idea here is now that we have that done when we come back we should not be able to move front to back or left to right that's because we swizzled but we didn't connect properly in our controller I just it cracks me up that it's called Swizzle okay so y now if we connect in our y we should have front to back now let's check that so this is front that's our W key and this is s this is our back key okay so we basically swizzling it flip the axis so it makes sense Y is up that's what most people are used to and by the way why is not up in World space let me be clear on this if we escape out of here what I want you to look at in the in the uh bottom corner okay Z technically vertical in Unreal Engine is z but what I mean by y being up is from our camera if I want to go toward the top of the screen that's Y and left and right is X also uh that is that is how the gam pad is set up as well okay so let's go ahead and connect in now our um ad so as part of our wasd controls so we're going to need two more we can just go ahead and create both of them we'll just go ahead and click the keyboard and click a and we'll go ahead and click the keyboard again and press D and then our modifiers we are going for the a because a is going to be the negative we're going to add in a negate and then for the D we are going to should just be free and clear so let's just see how this works save all okay so we have our up and down but we we actually forgot to connect in our left and right so this is up and down we can comment this or forward backwards let's call this forward backwards this is going to be forward back movement okay we also need to do left right and it's going to work the exact same except what we're going to do is instead of connecting in the Y value from our axis we're going to connect in the x value so that's going to be our scale that's going to be our scale also you don't need to worry about I just made it bigger so you all can read it a little bit better okay so now our x value is connected in but we need to get which way we want the input to go so this is going to be the Left Right values of our for our controller so much like we did before what we're going to do is we're going to get our control rotation and our forward vectors but instead of our forward vectors we're not going to get our forward vectors we're going to get the right Vector instead so let's just paste this in let's get the make some room here let's get the right Vector here's our right vector and we're going to split this now this one we do want the uh we want the X and the the because we're getting the right Vector we want the roll and the Y and we're going to connect that in so this gives us our right to left so let's just double check and see if we got that right so front to back still works that's great left works and right works that is it y all we have we have just successfully connected wasd that's great all right now we do need to make a couple slight changes because we want this to work for our controller so let's go ahead and show you real quick how to add the exact same thing to our controller and why the enhanced input system is so awesome because what we can do here is in our mapping context what all we have to do is add in a new Option here and that is going to be our game left Thum stick so this one I am going to type in it's game left thumbstick 2D axis all right and what I want to do with that is if we I want to show you what happens now this should just start working all right so we press play now it's not going to work right away I have to click to activate the window okay now when I activate the window now now I can use the thumb stick to move our character around which is pretty cool actually but there's a problem here's the problem when we are done moving watch what happens when I take my thumb off the stick why is the character still marching or walking or doing whatever they're doing the reason is because on a game controller or lots of different controllers depending on the type of controller is even though this thing is not moving there's a slight area in the Middle where it's kind of getting a little bit of input still it's almost like it's slightly engaged even though I've let go of it this is called The Dead Zone The Dead Zone determines how far you have to press before your character starts moving in a particular direction right now we have no dead zone so it is super sensitive and when I Let Go it doesn't actually stop so we actually do want a little bit of dead zone in this case so let's go ahead and add in a quick Dead Zone once again then our enhanced input system makes this easy so I'm going to add in a modifier here and that modifier is going to be the dead zone now if I just use the default values you can customize this you can even make this customizable for your game and your players uh but if we go ahead and press start and we click play now when I move my character around like before that's great and when I let go you'll notice the character stops the character doesn't actually start to move until I get at least some amount of pressure on the thumb stick now so we actually do want a little bit of dead zone and again in most games like this you can actually customize how much dead zones there but that's what it's for now you know okay now we have a new thing that we want to take a look at you'll notice so so we basically have all of our input set up we have Wy working we have the left thumb stick working that's great but for a twin stick shooter what we need is we need our character to do not turn to face the direction of movement we want the character to face wherever we're aiming with our Mouse and this is where we get into the mouse cursor stuff that we started with earlier and that's why we're doing we're using the top down template so what I'm specifically talking about is when I press forward notice where my mouse is over here it's pressing forward the character is facing forward I want this character to face where my mouse is not where I'm Wasing because this is where I'm going to be shooting so there in order to do this let's first disable that feature so in our character top down character I believe it's rotate there is an option and you're going to find in your experience that um a lot of Unreal Engine is finding the magic checkbox so in this particular case for our character there is an option here that says Orient rotation to movement and what that means is if the character is moving forward it's going to orient the character to Face Forward we're going to turn this off now I found that in the whole details but generally this is under the character movement makes sense that's where this happens so if I uncheck this now what I want you to notice is when we play if I go forward back left right you'll notice that my character is always facing forward no matter what I do this is what we want for a twin stick shoot absolutely what we want but what we need to do is we now need to add in the mouse component to get the character to look at where our Mouse is so let's do that over here in our top down controller this is where we put all of our front to back Etc this is also where if we look at it this is where they were getting the location under the cursor and with that if it was valid they were basically setting follow mode we're going to use the exact same kind of thing now how does this work if I double click on this what I want you to note is this is actually what's happening this is what's called a function if we come back here this git location under cursor is a function a function is a group of blueprint scripting that you can reuse all over the place and it helps it helps keep your blueprints clean and it helps organize it and it also is really great for making things more reusable if you want to go into a deep dive into uh blueprint functions and how this all stuff gets used I'll throw a link up here so you can take a look at that but what's important from this is is we are getting this is a a actual function that was created by a developer somewhere called get hit result under cursor by Channel what this is going to do is this is going to give me a location underneath the mouse cursor that I can then use to look at which is what we're going to do so let's just grab these I'm going to control C this is great about unreal you can control C control v a lot of stuff including your Blueprints and what I want to do is we need to make it so that our character will face the mouse so in our event graph let's go back to our event graph what I want to do is let's go ahead and we're going to keep this same kind of functionality yeah actually let's just reuse all this so I'm changing the plan here a little bit I'm going to take all of this now when first we have to figure out when we are going to look at our Mouse are we going to do it when we click no because we want click to be able to shoot also we want to be able to look around independent of whether or not we're actually holding our Mouse down the whole time we actually need this to happen all the time so for something to happen all the time it's important to understand what's going on in the background when the game starts uh time is moving forward and you can think about it as time moves forward the clock is ticking tick tick tick tick tick tick so as time goes by there is a concept in unreal called tick what that actually refers to is each tick of the clock do a thing okay almost everything in unreal or a lot of things in unreal can tick and your characters actually tick so what happens is each tick of the clock unreal goes in and as fast as possible updates all the visuals the the uh you know the bullets the collisions everything that's going on the animation all of it's happening on tick that's what tick is so what we are going to use is we are going to use the tick for this controller in order to always look at where our cursor is so that every time the clock ticks the character will turn to look at the cursor so let's just go ahead and do that in order to do that if we right click we can add an event this event that we are going to add is the tick event okay now just to show you how this works if I put put a print in here this is another function that you can use I'm going to print this print something called hello if we just press play you'll notice in the top in the left side it's just printing hello over and over and over again this is happening because every time the game ticks it moves forward in time one frame one tick is the best way to think about it it prints hello now okay but rather than printing hello what we want to do is we want to get the location under our cursor okay so this is getting where our cursor is on the map and it's taking that location and it's putting it in this variable now a variable wow there's so much to go over okay so a variable is a storage container it's like a bucket that remembers value there is an entire video series on how variables work so if you want to dig more into that uh go ahead and follow that link it's a great it is probably good to have at least all the fundamentals out of the way otherwise uh you know these can get pretty deep so variable stores a value in this in this case we are storing uh the cached destination which is where the mouse cursor is currently okay so now that we have our cach destination of where we want to look at what we need to do is we need to tell our character to actually look at that point so one thing we can do with that is if we get the controlled Pawn this is if you recall right now the self is the controller the controlled Pawn is the character that we're controlling what I'm going to do is I'm going to get that actor location location so this is the current location of that control Pond and then what I can do is I can take this destination and I can find the look at rotation so this is a nice little helper function that somebody wrote for us one of the developers wrote for us so we're going to get a rotation out of this which is great now what I want to do with this rotation is I now want to set the rotation set the actor rotation to be that new look at rotation now this is going to not work exactly like we want but it should show you how this stuff goes so let's compile save save all and take a look at where we are okay so we have a couple problems it is kind of working we can run but notice how our rotations are all messed up and it's because what is happening is the actor location is the center of the capsule which is slightly off the ground the mouse location is being projected down onto the ground generally speaking and so what happens is that Vector that goes from our character down to the ground has a vertical um a vertical piece to it and up and a down we don't want that you can see we're totally messing with our characters up and down so we need need to make some changes to fix that so one of the things we can do is we can go ahead and take this and convert this to D just the 2D portion of it just the X and the Y not the Z so let's go ahead and multiply this and what we're going to do is we are going to multiply this by let's um split this pin pin struggle let's go one one zero so that's basically going to zero out the z z aspect of it and then the actually we want this actually let's keep that one it's this one the actor location that I want to change let's split this pen struct so let's break this the target let's split this and what we're going to do is we're going to take this and we're going to split that we want the X X we want the Y we do not want the Z the Z that we want is we want the same Z as our cach U Mouse because we want our Mouse and our character to be on the same plane so that we get a flat look at so let's split this or let's break this so we'll break this and I want the Z value for this okay that way they're they're all on the same plane let's see if that fixes our our problem okay so if we play so you'll notice now our character turns to face wherever our mouse cursor is now we have a little bit of a problem and that problem is our character is actually it's all backwards right now so we need to flip this because we either connected this in our Target our start yeah we we actually connected these in backwards notice our cache destination is the start Point that's not the start point the start point should be our character so let's break this up again and reconnect it I can break this just by all clicking I am going to let's just reconnect everything and redo this all right so our start let's split this pin struct our start is going to be the X and the Y of our character and the Z of the mouse cursor and then our end is going to be the XYZ of the mouse cursor we can just connect these in like so XYZ okay so exact same thing just reverse order that should give us our facing to be what we want it to be now you'll notice this is pretty quick this is great so we can run around and our character now runs and faces as they're running even if I'm going backwards Etc they are now facing wherever our cursor happens to be which is awesome we are so close to wrapping up the input and control portion of this video so let's uh let's make a couple of quick changes here it would be nice if we could control how fast that rotation happens because what can happen is if we're here let me show you what I'm talking about if we're here and I flip to the other side it's a pretty quick pop now that's probably fine from a gameplay standpoint I'm not worried about that but if you get in here and you start trying to customize animations and everything like that it's pretty fast but we can control that what we can do is we can do something called an interp two what that means is take the current rotation I have and that's where I'm rotating two and rather than just rotating there right away in one tick what I'm going to do is over a period of time I'm going to do the best I can to get there as fast as I determine by an interpolation speed so let's go ahead and do that what I'm going to do is I'm going to take our actor rotation in this case this is going to change this a little bit so I'm going to take our actor rotation okay and I am going to take that and then I'm going to get the output of this which we have and so this is where we are this is where we want to be so I'm going to interp two interp two so here is a rotator interp two this is where I am this is my current this is my destination this is the target all right this is going to be our final rotation now what we need to do is we need to connect a couple of other things in here so one thing that we could do in this particular case we could connect in our Delta this is uh basically this is how fast time is ticking and then our interp speed let's set an interp speed of one for example and let's just see if that even works okay so we have interp speed of one now I moved my mouse look at how fast the character is turning it's doing its best to get there but it's very slow so even though I'm getting to the other side the mouse is flipping this is entirely too slow for gameplay like that's not going to work but I wanted to do that as an extreme so that you could see if I set my inter speed to 10 for example what's going to happen is it is going to calculate that change much faster but you can see it's not insane now it's not that quick snap that we had before okay so that way you you can control how quickly your character is going to turn based on the interp speed if we this up to 100 let's go 100 let's go Ludicrous Speed okay so now at 100 it's almost like it's almost like there was no interpolation all right so this is a great thing that we can use to control the visual aspects now where is this going to come into play eventually and we're not going to cover this in this tutorial but as you move your mouse around rather than your character sliding in a circle like this you might want to do some cool animation stuff like turn in place or uh you may want to yeah yeah turn in place is probably the biggest one but that's going to control how quickly your character can turn around and turn in place and we're actually going to do a a separate tutorial on turn and place I kind of like the feel of let's try I liked 10 I thought 10 felt good so we're going to keep this at 10 let's see if there's a way we can clean this up a little bit um this is just XYZ we can just disconnect these I'm going to do this and recombine this pen and the reason I'm doing this is because we'll upload this for the patreon members so you all can see that uh in a much cleaner manner uh actor rotation once again we want to and for all of you that are new it's really important we want to keep we want to keep our blueprints clean so that the next person that comes along and has to work with them can actually read them so let's just take this drw drop it over here that's a little more reasonable okay awesome so you think we're done with our base movement but we aren't quite done because we do need to test it on our game pad it's a twin stick shooter right so let's see what happens with our Gamepad if we try to use our game pad so walking works that's cool okay now let's take a look we cannot seem it doesn't seem like we can use our right thumb stick that's because we have not connected it so let's go ahead and add in the connections for our right thumb stick okay so in order to do that what we need to do is we need to set up a a new mapping context and the mapping context that we want to set up is going to be in this case this is going to be our uh what we need to do is we basically want to set up a mouse facing context or character facing context um but we in order to do that we do need an input action so let me go here and I'm going to add a new input action and the reason I'm doing this I'm going to call this input action Mouse face the reason is because we're actually going to get into a conflict with our Mouse and our thumb stick here in a second but basically this is the same thing it should be an axis 2D Vector that's great that gives me what I need in my context I can now go ahead and put in my Mouse face this is going to get this one we are going to use [Music] the uh thumb gam pad thumb right thumb stick 2D access okay and I think we want to Let's Swizzle it again just thinking that that's going to be a thing let's save that let's go to our controller and what we want to do is let's go ahead and take this and let's put our input action Mouse face we'll do that so this much like before what we have is we have our our triggered event and we have our access values So currently the way that we're setting our character facing is by is to set the actor rotation based on where our mouse cursor is however if we're using the thumb stick we don't even have the mouse cursor we don't even have to worry about about where it is so for now let's just disconnect tick okay ultimately what we're going to want to do is we are going to want to get our controller and we're going to want to set our rotation and the rotation that we're going to want to set is going to be the current rotation it's going to be a lot like this okay it's going to be the current rotation plus a value so let's go ahead and do that so with our controller what we're going to do all with our control Pawn let's get the actor rotation we'll get the actor rotation and we can go ahead and find the look at in this case find the look at again we'll use the same thing and the start position is going to be our current character location get the actor location that's going to be our start and I'm going to use Vector math now we probably probably don't have to do this can we get our can we get a forward Vector let's do this let's make a vector actually hold on let's make a vector make a vector and from that Vector let's get a rot uh rotate Rotator from make Rotator from let's try X okay and then let's split these values I'm going to split this pin struct and let's connect in X and Y let's see what we get here if we set this and this is triggered and we press play what do we get okay so if I press forward it's backwards backwards right left forward is back and back is forward okay so we're flipped right now so we probably didn't need to switch that is what I'm going with so let's take that and let's remove this as our Swizzle and let's try that again so we're facing forward oh we do need to rotate it okay so basically our actor rotation is off by 90° what I mean by that is when I press up up is to the left if I press left left is down down is right right and now so we're off by 90° so what I want to do is I want to take the result of this and I'm going to combine the Rotator I'm going to combine two rotators and I'm going to add I believe it's 90° here so let's go ahead and do that compile and save play now and let's test forward is forward is forward backwards backwards left right okay cool so let's see what this looks like when we play so we're moving around and I'm using my right thumb stick to move around which is cool so that is totally working twin stick shooter done not really but with what that means is uh what we want to do is we do want to do some of our nice interpolation so to do that let's go ahead and bring back we can get rid of this we don't need this we don't uh we do need that we'll bring that back in a second here okay so this is where we want to face this is going to be where we are facing get the actor rotation so this is where we are and we are going to redo this exact same thing we're going to our uh rotation Rotator inter turp 2 is basically what this is so this is where we are this is where we want to go to and that's going to be our final and we do need to do something tricky here because we don't have Delta here we're not in tick this is happening in our input but what if we're not doing input nothing happens so let's go ahead and this time what we're going to do is we are going to get something a little bit different in addition to the Delta we can also within a tick we can also get the world Delta and I can connect this in to here I'm going to set my interp speed to one just to test to make sure this is even working and see what happens okay so we can move and when I write left up down oh it's totally working it's just slow so let's bring back that same interpolation speed not 110 let's go 10 compile and save that and let's play that and see how our twin stick shooter feels oh got to click all right so as we move around that's cool now do we also have the same issue we have a little bit of the same issue we have a dead zone issue I think we need to put in our Dead Zone on this so that it doesn't happens because right now what happens is when I let go of the thumb stick it goes to face back where it was so let's see if we can put a dead zone on our modifiers see if that fixes that which way the character is facing issue so we're moving facing up right let go doesn't move perfect when I let go now it stays that way so now we have two versions and now for real we're done with our twin stick shooter nope just kidding we're not done we have a problem we have a little bit of a conflict okay and the conflict that we have is when our character is running around with the game pad watch what happens if I reenable the mouse so here we go back down to our top down controller if I reenable the mouse what's going to happen is every tick it's going to be looking at the mouse position but at the same time it's also trying to do the mouse facing input action from the game pad so let's see what happens when we try to play now if we move our Mouse it's working we can move using WD Etc but I'm going to leave my mouse in this top right corner I'm going to pick up the game pad now the moving around works but if I try to left face look what happens when I Let Go what happens when I Let Go is it turns to face wherever my mouse cursor is so this I can't actually I can't even face down to the bottom left because the tick from the character is overriding so here's what we're going to do while we are when this Mouse face is active we're going to disable the tick how are we going to do that we're going to create a new [Music] Boolean and what we're going to call is let's create a new bullan so I'm going to add a variable over here on the right this is going to be is game pad active and actually I'm not to put it B Gamepad so Boolean Gamepad is active and then what I'm going to do in here is when we get input from our Gamepad I'm going to go ahead and I'm going to set game pad to active as true okay and then up here what I'm going to do is I'm going to slide all this over a little bit and then in here I'm going to get gamepad as active and if this is active I'm not going to do all this so if the gam pad is not active this is called a not bullion I know this is a little bit backwards so gam pad is active not active then I'm allowed to tick so let's put in a branch here so we could do let me actually let me just clarify this for for your own uh learnings okay if the game pad is active what we want to do is if that's false in other words the game pad is not active we can connect in and run however it's just general good blueprint practice to prefer truth as opposed to false so either name your variables differently in other words um gam pad is not active or what we can do is we can flip the game pad active and use the not so is the GamePad not active if that is true we can go in here so now what we've done is we' set it up so that when Gamepad is not active we can do this so here we go we're using our Mouse we're running around that's great now when we activate our game pad now we're running around the minute I press this thumb stick now my game pad is active tick no longer works you'll notice that when I let go the character does not turn the face of the mouse that's because of that bullan variable that we added in there that lets us do this now if we go back to our Mouse it no longer works why not well it doesn't work because we need one more step in here if we are not triggering this in other words when it get gets canceled when it's completed Etc we need to set our game pad back to false so let's go ahead and move all of this stuff over let's take this and let's set our game pad let's just copy this and paste it and what we're going to do is on canceled or on complete we're going to set Gamepad active to false so let's go compile and save that press play okay so uh first test mouse and keyboard so WD is great follows the mouse that looks good okay now let's switch to the game pad so if we left Mouse now we've triggered our our our our Gamepad active State now at this point so we're now able to run around and move and do what we want to do and when we let go notice it already faces the mouse cursor I already know this is going to work so now our mouse cursor is active again so we have successfully set up our our gam pad and mouse keyboard versions for the input for a twin stick shooter so in all seriousness that that's awesome we we actually do now at this point this is not another false ending we actually do have all the setup done for our keyboard and mouse our inputs our character facing uh we learned a ton about the enhanced input Etc and now what we need to do is we need to or what we're going to do is we're going to make this look a little bit better better because right now when we run around the character is always running forward even when we're running backwards or left or right the character's running forward so in the next section what we're going to do is we are going to get a bunch of cool animations in here so our character will run based on which direction they're facing let's do it all right in order to dig into the animation BP uh or the animation aspect of our character what we need to do is we need to go on a little bit of tour of how animation Works in unreal so we have our top down character our character as we had mentioned before has a skeletal mesh on it this is the thing that the animation plays on in this case the way this is controlled over here on the right when we pick our skeletal mesh you'll see this section for animation and the way the animation is determined in this case it says use animation blueprint and the animation blueprint that it's using is this ABP Manny if we go ahead and find that asset and we open it this this is basically everything that happens in order to bring the final pose to our character on screen so let's talk about two main parts of this we have the event graph and then we have What's called the anim graph now if you want to go real deep dive we have videos on that on the animation blueprints you can check those out but the one thing that I want to point out if you're new is this aent graph this is where we kind of set up all the logic and the variables and get things prepped for the animation graph the one that I want to point out here here right now is when we come in here on our update of Animation we come in here we get our movement component we get our velocity we get and we go ahead and use that to set the ground speed now in our anom graph our anom graph has a couple different pieces to it we have our states our Locomotion and our final output pose inside The Locomotion State machine if you look inside of it you have an idle and a walk run the walk run is where that ground speed gets used and what it's being used for is it's being used to drive a blend space which is a special type of Animation sequence it's actually a blend space and and what the way a blend space works is you can combine different animation sequence to create a final output so let's take a look at this blend space reason being is we are going to be making one so if we open this up you'll notice that the character is walking in place that's because currently you'll notice that this access is set to speed this speed axis is exactly the same speed that shows up here that the ground speed is driving if we go back and I control drag to increase the speed our character starts to walk and then depending on how fast the speed is the character will start to run this is what we're making we are going to make a blend space that allows our character run forward backwards left and right and we're going to connect it in so that all our animations look way cooler and unreal so to do this we are not going to animate from scratch left and right and forward and back that's that's a whole other discipline so we do have videos on animation and things like that but what we are going to do is we are going to borrow assets from the Libra project the liar project is available for you in the marketplace and uh we're not going to go into it but the quick thing you need to know is under hero abilities manin animations Locomotion unarmed we are going to take a look at the jogs okay we have a unarmed jog these are the m so let's get the mm's we want the masculine ones okay so we have mm unarmed jog backwards we have mm unarmed jog forwards we don't need because we already have a forward we have a left and we have a right now what we're going to do with these is we are going to migrate these to our current project so let's right click and choose create uh not create asset actions where is asset actions migrate now this is going to get everything under the sun we don't need everything under the sun we only want the animation so I'm going to uncheck everything else because I don't want to junk up our project with a bunch of stuff that is not going to be used for now and potentially confusing especially for uh when I uh give these project files out to patreon members okay so here we go the only thing we're taking now is the forward or the backward left and right jogs all right we just go ahead and click on okay and we need to pick our twin stick mini game content folder we'll just go ahead and select that folder it is going to do the migration I am going to go ahead and close this down reason being is I've already done one blue screen to death so don't want to do another one now when we do that if we go back to our project folders you'll notice we have a Heroes folder now with mannequin animations Locomotion unarmed in it if we open these up and take a look at them you'll notice we have a problem if I double click on it oh whoops it can't find the skeleton the reason it can't find the skeleton is we didn't bring it over so we just need to tell it where the skeleton is and we know that the skeleton in this project is the same as the one that was using Lyra which is great so let's say yes and I'm just going to pick our SK mannequin skeleton and I need to do this for each of those but when I do that you'll notice that it opens up this character and uh it as a result of that let's see here should be able to delete these because we don't really need them these are all foot placement stuff and everything like that but whatever uh we digress a little bit let's go ahead and save that and so that's our jog right I believe let's do our jog left same thing we're going to get the skeleton warning we'll choose yes and we'll choose the SK mannequin it's going to do that that looks good and then let's do our final one which is backwards can't find it yes SK man again okay now this one when it opens up you'll notice I want you to notice that there's a difference the previous ones were in place this one is actually moving through space we don't actually want that we want this to be in place so I am going to dis aable root motion down here on the left to basically lock this animation in place all right and that wraps up uh migrating our assets almost I want to take all three of these and I am going to go ahead and move them into the Manny folder so let's move them here I'll clean up redirectors and then I'm just going to delete this Heroes folder okay one last thing I want to do with these animations is I want to change the default display asset to be Manny and so we'll click apply for that I'm going to do that for each of these three because I don't want to have to load load Quinn each time Manny asset that's the left and then backward just make sure it's Manny apply that to the asset we should be good okay so let's just save these three and now we have the animations that we need to create our blend space how do we create a blend space well what we do is we'll go to our mesh's folder I'm going to right click on Manny I'm going to choose create and I'm going to choose a blend space now the blend space that was there previously was one dimensional it only had one aess we need two because we have front to back left to right so let's just create a blend space this is going to be called BS for blend space move and let's take a look at how this works all right so the way the blend space works is down here we have our cardinal directions our left and right up and down right now you'll notice our axis our axes have no labels they're set To None over here on our left if we look we have a horizontal axis let's label this let's call this left right and let's take our vertical axis and call this forward back and we need to make a couple changes look at the minimum and maximum values on our axes 0 to 100 we kind of need to go backwards just as much as we go go forward so I'm going to change these to beus 100 to 100 in both cases all right now that our axes are set up all we do is drag and drop stuff onto it so let's drag our Ford uh we want mm let's get this forward so mm run forward I'm going to drag this up here so our character starts running right away because there's only one item in our tree right now and then we're going to go ahead and where's our backwards here's our jog backward I'm going to drop this down here and now if we control drag this is forward running and this is backwards running you can see the difference as we do this so now all we need is left and right right and left so let's see if we get these correct so left is going to go over here and right is going to go over here all right so now if we control drag you can see we have our right and our left I think we may have these flopped we'll we'll have to fix that in a second we have our up and down which is great and we do need one more thing in the middle when our character is not moving we don't want them running we don't want them left and right we want anything let's just go ahead and drop in an idle okay so here's what we need to do let's go ahead and make sure all of these are properly perfectly aligned over here on the left hand side we have our blend samples our mm run forward should be 0 100 so I'm just going to type these in so I get perfect numbers our backward should be 0 minus 100 our left should be 100 Z and our right should be minus 100 and our our idle should be 0 0 0 0 okay so now we're set up where everything thing is left right right left Etc that's all cool backwards forwards perfect let's save that and close it down or I'm not going to close it because we may need to flop left and right we'll see here in a second all right so now that we have that all we need to do is we need to connect it up now we know we don't need ground speed we have our walk run we're going to replace this over here on our right we're going to change this blend space to be our move blend space when we do that we get only one of our axes that's because unreal doesn't noce update this if we right click and choose refresh nodes now we have our left and right and forward and back so we have the directions but we have no way to drive them because we only have this ground speed so what we need to do is we need to create a couple or at least a variable that will allow us to drive this move so let's go back to our event graph because that's where we do that now just like we've done here we got the velocity what we're going to do is we're going to take the velocity all right and what I want to do is I want to normalize this the reason I want to do that is because I want to be able to make changes to it it is possible that as our character is going up a ramp or down a ramp that our velocity has verticality to it but remember to control our animations because we're doing a twin stick shooter we don't want any verticality to that so what I'm going to do is I'm going to take and I'm going to multiply this once again we have tons of videos on vectors or we have at least one video on vectors that you all can watch if you want to learn more about vectors but basically what this does is by multiplying this by one in X One in y and zero in Z it removes the vertical aspect of our character's movement and we can use this to create a new variable and that new variable we're going to call input 2D and I'm going to set this to be a vector to D and what we'll do is we are going to set that now reason being or the reason we're doing this is we need to be able to drive our character's motion so if we take this output and we just connect it to our input this is going to connect in and set our 2D input 2D Vector that we can use now all throughout our animation graph in our blueprint so let's compile and save and in our walk run what we want to do is let's take our input 2D we'll get it and we'll just split it let me split this been struck by right clicking left and right go ahead and compile and save now theoretically if we've done this right when we press play we should see our character run forward and backwards but we do not why so if you recall in our blend space remember our blend space goes 0 to 100 we took the velocity we normalized it to Direction so it only goes 0 to one so technically theoretically it is working but what is happening is we're only going 0 to one the reason I chose 0 to 100 is there is a world where maybe we want to add in the idea of a walk and so maybe between 0 and 25 it's a walk and we could add those into this blend space but for now we're not going to worry about it for the purpose of this demo I just wanted to talk about that so what I'm going to do over here here is I'm going to take this value the directionality of it and I'm just going to multiply it I'm going to multiply it by 100 okay and I'm going to do the same thing here I'm going to multiply it by 100 okay and then we're going to go ahead and connect this in now when we move forward we should get a run we do however we're getting a left to right run if we go left we're getting a forward and if we go right no if we go left we're getting a backwards if we go right we're getting a forward so what's happening is our input ordinals don't match our character facing so what we need to do is we need to come back and make a quick little change to our final input here so here's what I'm going to do I'm going to take this and I am going to rotate this I'm going to rotate this back VOR by 90° believe 90° so when I do this now what should happen when we play is if we run forward we have forward that's perfect if you go backwards that is definitely backwards if we go left that is our left run if we go right that is our right run perfect we're done right nope not done reason we're not done is because even though this works when we're facing forward look what happens when we face to the right if I face to the right and I go up W key right I'm running forward and if I go down I'm running backwards so what's happening is our characters run the input 2D that we're creating is not taking into account our character's rotation so we need to take into account the difference between our character rotation and the controller in order to properly get this so that we're always running forward based on which way we're going based on the mouse cursor position or thumb sticks so to do that in our Manny BP we are going to go back to our event graph and what we want to do here is let's get we should have a reference to our character and we do okay so with that let's get our controller rotation and let's get our actor rotation these are the two things that we said we wanted to use to Det determine whether or not we were how to how to properly account for the difference between now I just said the word difference another word for that is Delta so let's get the Delta between these two now that we have the Delta between these two if we take that and we connect it back in here it will work in the sense that it will start to account for the difference between the two however it will also still be facing the wrong way so we do still need this 90° offset so let's go ahead and add that in by putting a Bine rotators in here which just means let's just add so we're going to add our 90° back in here and then we're going to connect the output result of that into our rotating vectors let's compile and save that and let's go ahead and push play and test it so first base case run forward great back great left looks good right looks good now if we rotate 90° and I push the right thumb stick or D key do we run forward we do and if we go backward we run backward that's fantastic if I go up I'm running left now and if I go down I'm running right so now my character run makes more sense based on which way they're facing and it also works with uh the thumb pad okay now one thing I don't like about the thumb pad thing is when I let go the character instantly faces the mouse that's because when we put that can cancel out I would probably remove that if you're going to use thumb pad just disable it for the whole time but overall now whichever way we're facing the character is running properly based on what it is so we were able to take really quickly uh just a few animation assets feed those into our animation blueprint take that information and now our character moves so much better in the level it looks L it just visually is not nearly as distracting uh and we learned a ton about how the character facing the controller facing how the anbp variables work how to use those to drive a blend space so with all that everything's looking great what's next I'm thinking we need some enemies before we get into I mean we we can't get to a win condition if we don't have enemies to destroy so let's go ahead and set up some enemies all right in order to get our new enemy started what we need is we need a blueprint so unreal knows how to display it and what to do with it so what we're going to do is we're going to right click here and we're going to choose new blueprint class now the first three are probably the most applicable we have an actor a pawn which is just an actor that can be possessed that could be an enemy but then if we look one more we have a character which is a pawn that also includes the ability to walk around and for this enemy we want them to be able to walk around because we're going to be using the same um character meshes and animations and everything that our player is using for the purpose of this demo so let's just go go ahead and call this blueprint enemy base and what we are going to do with our enemy base is we are going to start to set up our visible visuals now as you'll notice when we load load this up it is just a capsule there's no visual set just like we described uh very early on in order to set the visuals what we're going to do is we're going to choose our mesh component over here on the left and then over on the right we're going to set our skeletal mesh to be Manny now one of the things I want you to notice is when Manny comes in Manny is floating off the ground because Manny is actually based on where the capsule is halfway up the capsule if we were to drop our enemy into our scene and take a look at it you'll notice that the character is floating just basically way above the ground the reason for this is because once again the capsule is the one that's doing all the work the visual is a magic trick to align and make to give the player the illusion that the enemies are actually moving with it so what we need to do is let's move all this stuff down we're going to take our mesh how far do we move it down well we could just eyeball it move it down till it looks like it's good or we can take a look at our capsule component and we can see that it has a half height of 88 which is how tall it is and we can just type in a88 here for our zv value and now our character feet will line up with the ground perfectly which is great let's compile and save that now the next thing that we want to do is we want to make it so our character can uh move to kind of bring that illusional life so we're just going to reuse our Manny blueprint for now I'm going to show you a couple problems with it here in a minute and when we take this now and we look at our character in scene we now have an enemy we actually have an enemy in our scene which is great however if we had more than one player or for visual uh Clarity it would be nice to know and very quickly be able to identify where the enemies are versus where I am shouldn't be too bad cuz we have a locked camera right now but in general it would probably be great to be able to differentiate these two so to do that we are going to talk a little bit about the materials if we take a look at our mesh over here on the right just below it you'll see we have materials we have a material instance for manny2 and one for manny1 I'm going to click this to browse to the asset and I want to show you a couple things a material instance is an instance copy of a parent material let's take a look at Manny 1 okay now when we look at man1 what we have here is we have a bunch of options that we can change we can change the textures and the tints and uh all kinds of different things this is actually all given to us as options as a result of the parent material if we open the parent material down here on the right we can actually just browse to that and open that up you'll notice a distinct difference between a parent material an actual material and a material instance this has the entire graph of everything that's going on this is all of our colors this is all of our Ting everything that is goes into this material and gives us the options that we have when we look at this material instance this is done because uh it's an efficiency thing it's a whole lot easier to have one material with slight variations than it is to have every single material in your game being the same thing so this is material graph there's a lot that goes into it there's separ separate topics on how that works but for the purpose of us what we are going to do is we are going to reuse these Manny material instances and we're going to make them red so let's take a look at these instances I'm going to create a new folder over here called enemy and then I am going to copy the Manny materials into the enemy folder and when I do that I'm just going to choose copy here now if we look at our enemy folder I'm going to rename these so it's clear these are enemy1 now and enemy O2 and then what I want to do is I want to change colors so let's go ahead and let's just change the tent of this so we're going to tent this to be red for example and let's save that and then let's go to our second material and we'll do the same thing we will change the tent so we we in order to change the tent we need to check the box turn this on I'm going to use the same values 10.25 you can use whatever colors you want let's go ahead and click save and then what we need to do is we need to set our enemy to use those materials now we don't want to change the base skeleton mesh but fortunately because the way all the inheritance and everything works is we can just change the material for our enemy base so over here on the right what I'm going to do is I'm going to replace Manny O2 with enemy O2 and I'm going to replace Manny 01 with enemy 01 and now you'll notice that we have a nice red enemy to work with and when we look at this in the level it is a whole lot easier to see who I am versus who the enemies are which is great now what would be awesome is if we could get our enemy to move relatively quickly and chase us so let's see if we can't set that up and the way we're going to do that is in our event graph for for the enemy what I want to do is I want to just simply tell it to chase us when it spawns okay we're not we're we're not into AI or anything like that yet simple just for testing let's on begin play let's do a simple move to and we're going to do a simple move to actor the actor we're going to move to is we want to chase the player let's get the player Pawn we're going to get the player pawn and that is going to be the goal that is the goal of this move to and then the controller that is going to be doing the moving is the enemy's controller so right now we're in the enemy blueprint let's get the controller and what this is going to do is it's going to get the controller for self because my S from the frame of reference of the enemy is the enemy and there we go and now we have it now if we save this I'm going to move my enemy a little further away for now and then when we play let's just see if they start running towards us they do now the interesting thing is as they're running towards us notice there is no animation why why aren't they animating the reason for this is in our animation blueprint the easiest way to find it is in our enemies if we click our mesh and we go to find our animation blueprint take a look at this what we have here is everything should be working logically in the sense that this is a character we know it's a character when we initialize our animation so we're setting our character that should be valid this is our character movement that's also valid but look at what happens down here we set our ground speed that's great but down here we we set this variable should move and should move is being set based on the movement component's current acceleration and whether the ground speed is greater than three the current acceleration is determined by the player pressing the thumb stick or pressing wasdi if we don't have acceleration if we go into our Locomotion let's see here let me show you where we are in our anom graph if we go into Locomotion we go into this you can see this is a state machine this an animation State machine the way this works is we come in here we play idle and then these conduits have rules the rules that allow you to transition to walk to run or back to idle and in this case the rule that is being used to transition is should we move so if should we move is false it will never get to walk run so what we want to do is go back to our event graph and we need to find a way so that if this is an enemy we would set should move now there's a couple different ways to do this we could create a whole new anim blueprint for enemies we could or or which ultimately you'll probably end up doing depending on how your enemy set up but in this case just from a Simplicity standpoint here's what I want to do I want to take our character and I want to do one more cast here what I want to do is I'm going to take our character let's see here our references and I'm going to cast that to an enemy and if that is true I'm going to create a new Boolean variable okay and that Boolean variable is going to be um let's call it enemy is enemy is enemy okay and what we're going to do with this is we are going to set this his enemy I think before I call it AI controlled but I've had a couple of blue screens so that's why that was there before so if that's true we're going to set is enemy if it if the character is an enemy then we're going to set it as his enemy then all we're going to do down here is we are going to go ahead and if our ground speed is greater than three and our we have acceleration and let's put an or in here or our character is an enemy then we're going to set should move to true so ground speed greater than zero that's going to be true if it's moving and current acceleration might be false but if it's an enemy that's going to result as false or true which will be true and so we should get movement let's go ahead and compile and save that and let's go ahead and play look at that our character our enemy is now running which is perfect and then when they get to us they stop now the interesting thing about our enemy is they are not facing their movement so we may need to turn our character I think our character is 90° off let's take a look at our mesh in the viewport and see which way it's facing ah okay take a look at this our capsule look at which way our capsule's facing you can see it by this blue arrow look at which way our enemy is facing okay our enemy needs to be rotated 90° so let's go ahead and rotate this 90 or minus 90 actually okay so let's try that one more time Press Play There we go our enemy is now turning to face us which is cool so our enemy is now chasing us now there are a couple things like uh why do they stop when they get to us that's just part of the condition of this simple move too when they reach their destination the character is going to stop now we could try a different move too here we could try an AI move to so let's do this let's do AI move to to see if we get a different response from that okay so the pawn is going to be ourself in this case and our Target actor is going to be the player and we are going to do try an AI move too this may this may still stop when it gets there because it's not actually renewing itself so let's just see if it does the same thing nope uh yeah it does stop it stops when it reaches the acceptance radius so what we're going to need to do is we're going to need to put in logic where if it reaches us it will keep trying to reach us but overall we have successfully dropped in our enemy and made it so that the enemy will chase us around we set up the visuals and all those kinds of things now what we need to do is we need to set up we have a couple options now what we could do is we could set up the ability for the enemy to do damage to the player which I think is a good idea and then after we do that we're going to give the ability for the player to fight back so let's go ahead and set up some damage using some components here we go all right so in order to do damage we need two things we need health and a way to do damage so let's talk about health first generally speaking health is a floating Point number it's 100 Point 100.0 93.2 whatever that Health happens to be and what we could do is we could simply take our hero character we could add a variable like this call it health change it to be a float and then what we would do is anytime that we want wanted to do damage we would just reduce this health value however that is not very sustainable we can't reuse it so what I mean by that is then if I want to put Health on the enemy what I have to do is I have to open the enemy blueprint I have to add a variable called health and anything I make change wise to the hero I then have to do to the enemy that's not that's not awesome so even though this is a beginner tutorial I still want to teach you all to think modularly and reusa for the future so what we're actually going to do is we're actually going to create our own component and this does a couple of things but first let's start with I'm going to delete that Health variable let's just start creating our own component so over here in our gra U I'm sorry in our content browser I'm just going to right click and choose uh blueprint class and I want an actor component we're going to call this component health now there's a couple uh interesting things about our health component it's a little bit more reduced version of a regular blueprint you'll notice there's no viewport or anything like that but here's the cool thing we can take this component and we can add it to any character we want and the character will get all the abilities that are within that component so what I mean by that is let's take this health component and add a couple variables because we need a couple variables to work with so we're going to add our health this is going to be a float and then I'm also going to add Max health because what I want to know for a character is I need to know their their maximum health so I can properly display damage and things like that so we have health and we have Max health and then what we want to do with this component is we want to add it to our hero so just like we've been adding components so far actually let me compile and save this real quick all all we have to do is Click add if we type in health we can choose our health component now the cool thing is with this with this health component you'll notice that over here on the right I have the default values for health and Max health I got those just by dropping this component on the character so everything we do to the hero now we are going to do the Enemy by adding the health component so now our enemy has a health component and what that means is they also have a health and a Max Health which is awesome so we're going to get the enemy Health almost for free as we do this so here we go with our health component now that we have it what do we need to be able to do well let's do a couple things here first off on begin play for the health component the first thing I wanted to do is I want to set my health and what I want to set my health to is I want to set it to my Max Health reason being is uh just as anti ization step if a character's Max health is 100 generally speaking we want to start at the max health so let's set our default value for Max Health to be 100 we'll compile that and save it now what we need to be able to do is we need to be able to change the affect it so here's what I'm going to do I'm going to add a new custom event and this custom event is going to be called event affect health and in order to affect the health we need to know how much we're going to affect it by so what we can do with events is we can add something called an input so over here on the right I'm going to click on input and I'm going to call this uh amount now this is also a float you want to set this and if the idea of variables is new to you Etc uh it may be worthwhile to go back and check out some of the fundamentals videos so this is an amount and now what that means is when we start with our when we call effect Health what we can do is we can set our health now here's the interesting thing about effect Health what we want to do is we want to set our health equal to the current health plus the amount now why do we want to use plus the amount we want to use plus the amount because the amount that we're affecting the health by could be positive or it could be negative which is cool because this event Health can be used to also heal characters or anything in the scene that has a health component for example so what we're going to do is we're going to come in effect Health we're going to add the amount to the current health and then we are going to set that as our current our new value so if I started at 100 and my amount was 50 my new health amount would be 50 okay now let's go ahead and do another thing once we have our health let's go ahead and see if it's less than or equal to zero and if it is what I want to do is I want to destroy our character now ultimately this is not what we're going to do but I want to show you what happens so let's get our owner and the owner is the owner of this component who is this component on so we're going to get our owner and we're just going to destroy our actor now what this is going to do is once Our Hero's Health goes down below or equal to zero it will destroy it and actually that goes the same for the enemy but before any of this works what we need to do is we need a way to do damage this gets into uh a little bit more of the other component we're going to be adding to help us do all this we are going to add a box Collision here this box Collision is going to be if we look at our viewport it's going to be out in front of our character okay and the idea here is whenever this collides with the hero it's going to apply the damage it's going to do damage all right so let's go to our event graph and what we want to do is we want to add an event so on overlap on overlap so whenever anything overlaps this box what I oops okay so with the Box selected if I right click I can choose add an event for the Box and I want this to be Collision so on component begin overlap all right now what I want to do is what I could do here is I could get the overlapped actor I could cast this to a top down character and if it's true then what I could do is I could get that component get the health component and with that I could affect the health and I could set it to let's just say -200 just so we can see what happens when our character gets damaged this is ultimately not how we're going to do this and I'm going to show you why here in a second but theoretically when this box overlaps our top down character is going to affect the health which is then going to cause our top down character to look at its component and then our health component is going to set the health it's going to be less than or equal to zero and then we're going to destroy our actor so so let's just double check that all of our health is right it is so let's go ahead and press play now if he catches me I die and basically it just vaporizes my actor so you can see here we've we've popped completely out of our game that is not the way that we want to destroy our characters there's basically what we want to do and we're going to go back to the to the health stuff here in a second or I'm sorry to the Collision stuff here in a second but the whole point of getting the Collision working was so I could show you what we're going to do with damage what I want to do is something different if it's a player or an enemy so what we need to do is we need the idea of a Boolean [Music] Boolean enemy is enemy let's go is enemy okay so and this is going to be a bulling all right so what we'll do is on begin play I am going to get the owner and I'm going to cast that to an enemy base if it succeeds then I'm going to set this to true for example if it doesn't succeed it will stay false and either way I want to continue on on so I want to get the owner and I want to get the controller not the AI controller let's get uh actually let's cast this to a character and then as a character we're going to get the controller get the controller and then we can take this controller and we can cast that to player controller now I'm on the fence maybe we store this I think we going I think we should store this so what I mean by store this okay first off a couple things to go over what is all this casting stuff we've talked about it Loosely so far but basically it's just a way for me to say take whatever the value of this thing is and try to see if it's a character if it is a character great go do this if it's not we're we're just going to fail out okay then with the controller what I want to know or with the character I'm going to get the controller and I want to know if this controller is a player controller it could also be an AI controller for example if it is a player controller what I want to do is I want to store this I'm going to promote this to a variable so this is going to be our player controller variable and I have a feeling we're going to need this later so I'm just going to make it now so if it's not in any base we do still want to go ahead and try to see if it's a player so make sure we get this around so that way if it's not an enemy base we can check um make sure we check the box as well there we go all right so why did we do all of that we did all of that so that we are set up down here where what we can do is if if it's less than equal to zero we want to check to see if it's an enemy okay if it's an enemy if that's true then we can just destroy it because an enemy we don't have to do anything fancyful okay so we'll just destroy it if that's false let's get the player controller and see if it is valid now it wouldn't be valid if so right now if we were to put this component this health component on the player or the enemy that covers both but what if we put it on a spawner or uh door or anything else that we want to be able to do damage to so we need to do one more check here we're going to check to see if the player controller is valid if the player controller is valid that means we need to do a little bit more work with our player so let's just take this and there's something like input no it's uh it's actually disable input so what we'll do is we'll disable the input so what should happen this time when we get destroyed is it should come in here and just make it so that it's disabled now actually the way this this takes let see what this takes this takes an actor and a player controller so actually we need to change this we're just going to try to use just the player controller for all of this let's see if that's what it is yep that did it so uh I just plugged a player controller into both of these so what that does is that makes it so the input is disabled so now we can no longer move thought maybe maybe we can have a little bit more fun with this and maybe we can just I can show you all how to rag doll your character so after we disable our input let's do this let's get the controlled Pawn I know we just deleted that node but let's get the controled pond and what I'm going to do is I'm going to do something called um get component uh by class and the classic component I want is a skeletal mesh component so what I'm trying to do here is I'm trying to get a reference to the skeletal mesh component so that I can do some cool stuff with it and the cool stuff I want to do is I want to set Collision enabled and the Collision enabled setting I want to use is I want it to do physics and query query and physics because I want it to basically do everything it needs to do and then what I want to do is I want to set simulate pH physics on that skeleton mesh I'm going to set this to true and connect this in so very quickly we were able to grab the information we need and now when we get destroyed we should rag doll there we go we got it okay so our health component is already doing really cool stuff now let's go back and let's talk about uh a couple things with our health component we're going to compile and save so right now the way this is working is when our enemy base overlaps with something it's trying to cast it to check to see if it's a top down player this is not the most efficient way to work because what that means is we are going to have to as the player we're going to have to check for the enemy as an enemy we're going to have to check for the player if there's a spawner in here take any number of things that you could possibly use we can't we don't want to have to check for all of them so what would be really cool is if there was a way we could just send a message that's saying hey if you understand how to take damage or affect Health do it and if they don't understand it it's just like a foreign language they just ignore it well there is something for that it's called a blueprint interface all right we are going to be using a couple of them I think throughout this tutorial if you want a deeper dive you can go ahead and watch the videos uh there should be link around here somewhere but overall the easiest way to think about it is a blueprint interface is a messaging service and it works just like I described the enemy is going to say hey the person I just hit the thing I just hit do you know understand how to affect Health if so affect health and then the the spawner or enemy or player whoever is there they're listening to it if they know how to if they know how to listen to that message then they will affect the health if they know how to otherwise they'll just ignore it and go about their merry way so here's what we're going to do we are not going to do this cast Okay we we are possibly going to nope we're not even going to do this effect Health all right none of that what we are going to do is we are going to make a blueprint interface okay so over here I'm going to right click and I'm going to choose a blueprint class and the class that I want is actually know that sometimes is hard to find here so let's go blueprint and there's a blueprint interface one that's the easiest way to find it this is going to be a blueprint interface and this is going to be Health now these are weird okay if you think about it as a messaging system you'll start to wrap your head around it if you don't understand this it took me a long time to wrap my head around this so like I said go watch the video if if this is too confusing now it shouldn't be we should be okay so all we need to do is tell this messaging this uh blueprint interface what kind of messages it knows or it can deliver currently right now the message that it delivers is called New function we are going to create a function called effect Health effect Health what this is is this is saying that this messaging system this blueprint interface knows how to affect health and it can send a message it can receive a message and send a message to affect Health now just like our original effect Health we do want an input and this is going to be the amount and we want this to be a float that is it almost our messaging system is is built to affect Health but now what we need to do is we need to tell each of our characters to listen for it all right so I'm actually going to come back to our let's start with our enemy the way this works is under your class default or class settings there is a implemented interfaces remember we just created a blueprint interface if we click on this add option and we type in here Health you'll notice that the blueprint interface Health that we just made shows up once we do that look at what happened over here on the left there is a new function here called effect health or event and what I can do is I can rightclick on this and I can Implement that so if somebody were to tell me to affect the health I could respond to to it now I can do the same thing the other way so rather than doing all the casting and everything in here all I'm going to do is I'm going to take this other actor and I'm going to type affect Health see how it's a message so what this is going to do is if I overlap another actor I'm going to affect the health by a negative let's say let's keep it at 200 for right now okay we do not need this here right now okay so now that our enemy is saying is sending the message to affect the health let's go to our hero we need to do the same thing in our class settings we need to implement the interface we need to tell the hero that it understands this interface this messaging service for health and all we want to do is this one we are going to implement this so if you notice it popped up over here on the left I'm going to implement this event so down here what I want to do is I want to take my component health and I do not want to confuse you on this but we're going to affect the hell so I wonder if I should rename this just for this to be I'm going to rename this real quick I'm going to go back to our blueprint interface and I'm going to call this do do effect health because I want you to be able to see the differences okay so when we do that you'll notice that uh we need to compile this delete this and we're going to right click and implement this event okay so you'll notice that this is the interface call this is the message call event do Health event do effect Health let's make sure our enemy is doing that here we go this is our DU effect Health it updated okay so with that do effect Health what we're going to do is we're going to call effect Health from the component so this event is actually the one that we implemented originally in our component if we double click we can go and see this is what it does this is this does all of our ragd dolling and everything that we had already done so basically let me compile and save all this stuff basically our hero is going to get a message do you know how understand how to affect Health yes I do and this is what I'm going to do with it and that is it okay so let's compile and save this and as long as we got this all connected properly we should still do the same thing there we go we're affecting our health that's all done without casting anything without having to put in are you a spawner are you an actor are you a destructible are what are you I don't have to do any of that I can just say hey affect health so that's awesome all right so now that we can affect Health the other thing that we would like to be able to do is we' like to be able to see how much health we have left so wouldn't it be cool if we had a health bar so let's see here and actually just before we hop to adding a health bar let me let me add one more comment our enemy is currently able to do the affecting of the health to do damage we have not added that ability to the hero we are going to do that later when we get into the hero's ability to uh shoot projectiles and defend itself so back to what I was saying we're going to be creating a health bar so we've got a whole UI lesson inside of our miname so let's go over here we're going to our folder I'm going to create a new folder here I'm going to call this UI and in this UI what we need is what something that unreal calls a widget so if we create under the user interface a widget blueprint I'm going to create a user widget so the U uis that pop up generally speaking are user widgets in Unreal Engine all right so we're going to call this uh widget Blueprint Health bar okay now when we open this let's go on a quick little tour there are two main parts to a health bar there's the visual part that's all done in the designer and then there's the uh implementation the functions the events the logic that is all in the graph the event graph so for us what we need is we need uh a health bar visual so generally speaking the way these work is you need to put down like a a container for everything to sit inside the container I'm going to use is a canvas panel so I'm going to take this I'm going to drag this in here this is going to be where our health bar lives and then I also want to create a progress bar this is actually going to be our health bar and you can see it's a nice nice looking progress bar so I'm going to set the size of this to be 100 by 10 and then what I want to do is I want to set our progress bar size to be 100 by 10 as well so let me zoom in here and also let me make everything a little bit bigger sometimes when I when the system crashes I forget to do that okay so we have our progress bar now the way a progress bar works is if I click on this let me show you it has Style Style so what we're going to do is I want to change the background tint and I'm going to change the background tint to be let's just go something like that maybe a little deeper red so that's what it'll look like when the progress bar is empty so I want it red because that's bad okay now when we are filling it we want it to be let's make it a nice bright green however you don't see any of the green the reason you don't see green yet is because it has to be filled by a certain percent so if we change this to 50% let's compile this hold on a second uh fill color and opacity oh I changed my opacity okay so I accidentally typed in a zero for the alpha okay so back to what I'm showing you in the you can fill this bar by changing the percent well that's really cool because we also have a Max health and a health so we can use those to fix out a percent that's awfully convenient okay so anyways back to what we were doing we have our health bar now what we want to do is when when we add our health bar to our character it would be great to get the health component information at the same time so what we're going to do is over in our graph I'm going to add a variable and once again variable is just a bucket it's it holds information it holds a value in this particular case this is going to be our um health component component and what I want the type to be is an actual health component health component object reference so now what I want to do with this is when this gets added I need to make sure that I can edit these values so in order to do that in Blueprint what we do is we set it to instance editable and expose on spawn now I'm going to show you where that shows up here in a second so we now have [Music] our basically I'm just going to delete all these for now we don't need any of them we basically have the ability to set our health bar component however we need to connect that somehow to our widget our progress bar widget so over here what we can do is we can do something called binding now you're not going to be able see this because it's off screen but basically we can bind and we could bind to that to the health component or can create our own binding so what I'm going to do is I'm going to create our own binding and when we do that it pops up a a get percent binding now what I want to do is I want to take my health component I want to get the current health and I want I want to divide this by the max Health get the health so here's the max health and we're going to divide this divide Okay so what this is going to do is using this health component it is going to and we could probably put in an is valid here just in case but basically it's going to figure out the percentage and that is going to drive how much green is visible for us this is awesome so we have our widget made now we need to use it so first things first let's start with adding it to the hero character so back here in our event graph actually before we even do that let's go ahead and add it as a component so we're going to add a widget here this is going to be empty to start with we're not going to do much with it and then in begin play Let's Take begin play we need to begin playback what I want to do is I want to create a widget and the class of widget I want to create is a health bar component or a a widget uh Blueprint Health bar and what I want to show you is the minute I set that value look at what showed up here here health component so what we want to do is we want to plug in our health component to here okay so that way when this starts it actually gets the health component information straight off the bat now this isn't quite done yet the next thing we need to do is we need to set this widget to be this created widget so let's just go ahead and set widget and the cool thing is it'll automatically kind of set that connection up for us okay so now that we have all of that let's save everything and let's see what this looks like I'm not expecting this to look right so when we press play why don't we see our health bar okay let's go back and talk about a couple things this widget you have options for how it's displayed you can display in World space or screen space so just this one little switch let's go ahead and switch this to screen space I want to show you now all of a sudden we have a health bar however our health bar is way by the way it's working it's pretty cool the minute we lose all of our health we get knocked down to uh zero and the whole bar goes red so it's working which is cool however it is actually offset so let's take a look at what is going on with the offset if you look at our viewport what I really want is I want this widget to be right above our character's head however the problem is there's a whole bunch of weird offsets that are baked into the UI stuff so we're going to need to make a couple of changes so first off let's go back to our health bar there is the idea of anchoring something to a canvas panel where does it get anchored to if you look up here right now I have this in the top left corner well the problem is that left corner gets used as an offset on our character and so it spins around in weird ways so what I want to actually do is I want to change this anchor to be in the middle dead center all right and that's going to help us get that widget aligned straight over our character's head without any extra offset so let's just see how we're doing so already just that change alone has got the widget just right above our head which is perfect okay now let's go back and make a couple changes I'm going to do 50 damage instead of 200 and the reason I'm going to do that is I want you to see that the health bar only goes halfway it's awesome right okay so that's great so now what we can do is we can take damage Dage as the hero or our player character which is awesome and we just we did that simply with the effect health and we have our health bar widget okay so let's go ahead and do the exact same thing for the enemy now you might be wondering the same way that we made a modular component for health and a blueprint interface and we're we're thinking all you know reusability and all those why didn't we do that with that the health bar the reason is for the case of the hero I actually think it's going to be a little distracting to have the health bar above their head we'll probably want to move that to the heads up display the HUD later so let's just go ahead though and take all that work we did for the hero and just copy that in here so here we're going to add a widget okay and that widget is going to be in screen space and then what we'll do is we'll take our top down character and we'll just grab all of this and we can just paste it in after our begin play okay actually I'm going to do this after our simple move too which is also going to be changing later on uh when we get back to fixing the hole it stops when it gets to where its destination is okay so now what we should have is we should have a health bar over enemy we should have a health bar over a hero and uh the health bar over the enemy is probably going to be in the wrong place it is it's right around uh the pivot so the reason is we did not move our health bar in the viewport to be above the enemy's head so let's go ahead and do that now all right there we go and now we have everybody's got health bars except I cannot do anything to our enemy so we are going to need a way to do damage to the enemy to make sure it works the other way so at this point we have everything that we need so that we can set up our hero to be able to defend themselves so what we want to do now is let's go ahead and give our hero the ability to attack we're going to add an input to attack and then we also need to create a projectile for the hero character to attack with so let's hop in okay so to add inputs what we want to do is we're going to go to our input actions and I'm going to create a new input action I'm going to call this input action let's just do primary attack primary attack just in case we make another attack later we're getting so close to this starting to feel like a game let's open this up this is not an AIS 2D this is a digital bull it's basically going to be when you press it that's it all right so this is our primary attack input action now we need to add this to our mapping context we need to map keys to it so let's do that so under inputs and our mappings let's add our input primary attack and on the keyboard and mouse setup wasi we're going to make that a single left click so I just click the keyboard and do our left Mouse and we need to add it for our gam pad now for a Gamepad um for me I'm going to make it the trigger I think okay so I just clicked that button and then pulled the trigger and it filled it in for me which is great so now we have a way to attack all right in our hero character if we go to our blueprints and we bring up our hero character we have begin play we have effect Health we can Implement uh do we want to do this here let's do this on the controller actually because that's where everything is so here's our top down controller so our Mouse fa is in here let's put our attack in here okay so input action primary attack input action primary attack what I want to check is when this gets triggered print string hello so let's see if we got that set up right I do a lot of print strings I like to check to make sure things are working along the way so if I left click you can see it's printing hello now interestingly enough it printed a lot of hellos so if we take a look at why that's happening that's going to be important inside our left Mouse button we have this is our left Mouse button and this is our input action our input action is a digital bull but but we are not actually using pressed so for example what we can do here I'm sorry keep flicking back and forth in our triggers what we can do is we have a lot of options we can say is it held down is it h hold pressed pulsed Etc if we change this to pressed okay what I'm going to do is I'm just going to now you'll see it only prints once even when I hold it down so I want this to be set up so that I can so that I can neither click or hold but point is at this point we know we got our input correct because it is actually printing hello now what we actually want to do when we attack is we want to trigger an attack we want to spawn a projectile but in order to spawn a projectile we have to create one this is going to be fun so let's go back I'm going to take uh top down I'm going to create a new folder I'm going to call this game play okay and with gameplay in here I'm going to right click and I am going to create a new blueprint this is going to be an actor okay and this is going to be our blueprint projectile base we are going to make a simple projectile okay so projectile base is going to get a special component and it's going to get a component called projectile movement now what this does is it's nice enough to handle all everything to do with projectile movement for us so one of the things I want to do we're going to keep this simple we're going to set our initial speed to let's say 2,000 and our Max Speed to 2,000 we'll just keep it like that I do not want gravity I'm going to turn off gravity because I want it to shoot in a straight line now this is cool there should bounce we can put in bounce and stuff like that I also want to make sure all that's there okay great so we have a projectile however we have no visual we can't see this projectile so let's just add a sphere so we can see this that is a very big sphere let's try 0.1 0.1.1 um I'm not sure how big that is yet but let's add a collision sphere as well Collision sphere Collision okay so and I'm actually going to move this up here okay so we have our sphere and we have our sphere Collision what I want to do is I'm going to make this sphere match the size so that's about7 I think okay so this is our visual now this uh you'll be able to see this as I it it shoots through the scene if it's big enough and we can adjust it and then the Collision is detects when it hits something but for right now let's let's just see if we can get this thing to shoot out of the front of our hero character when we click the button so to do that what we're going to do is in our controller which is here for now what I'm going to do is I'm going to spawn an actor from class okay and the class we're going to spawn is our projectile projectile okay and let's just save all for a second now this needs a transform so in order to get the transform let's get our controlled pwn get the control pwn and I'm going to get the transform get the actor transform and we're going to feed this in here okay and the instigator is going to be the controlled Pond we may use that later let's compile our air went away so now when this gets spawned it is going [Music] to well it's going to get created but unfortunately it's not going to quite work the way we want to yet so let's go ahead and I'm going to show you just you can see oh actually it does interesting okay well hold on that that went way better than I thought it was going to go uh so let's see here what we need to do and I know why it's because we haven't turned on the Collision yet but that's okay so what I want to do is I want to turn off my enemy my enem is running around I need time to test so on begin play I'm not going to do the move tip okay so that way we can test all right so now that we have some peace and quiet from our enemy if oh it is actually doing it look at what happens when I shoot it moves my character out of the way that's not what we want but if I face this way it is working in the sense it is shooting this projectile in the direction we are facing this is cool this is very cool all right let's do a couple things let's take this projectile base and first off we can make this a quarter of the size uh let's reset this angle .25 and then also we're going to change this one to be 0.25 as well I thought I turned that on having troubles with the keyboard okay so let's see if that sizings a little better play okay yeah size is way better we'll probably go eventually smaller than that but for now that's that's much better all right so what's happening is when our projectile hits our player or our enemy what is happening is it is causing the Collision we don't want so and that's because this sphere our temporary visual has Collision turned on so over here on the right we're going to go down to Collision section and we're going to turn off generate overlap we don't want to be able to step on it and we want to do no Collision the reason we want to do no Collision is because we don't want the visual to be the Collision piece because we're going to remove this visual later and we're going to replace it with cool effects um so what's actually going to be the Collision piece is this sphere Collision up here all right so let's go ahead and play now you'll notice that my character doesn't move as fast as I can tap we're getting there okay so we have a projectile it spawns but we need our projectile to be able to do damage this is where blueprint interfaces come in again which is awesome all right so first let's go back to our projectile remember our sphere our visual sphere is no longer overlapping or doing anything we need to take a look at our Collision our Collision sphere we want to we do want to generate overlap events we do not want our character to be a stepped on up on and we're going to go ahead and we are going to overlap all Dynamic that sounds good okay and then what we're going to do in our event graph is when we get our overlap overlap so on ventor event actor begin overlap you know what I want to double check and make sure that's the one ad event ad event [Music] on hold on let's see here right click ad event on opponent activated hit begin overlap here it is okay that I didn't I knew that seem suspect also that's a much easier way to get those events okay so here here's what we're going to do in this begin overlap all we're going to do is if the other actor we're just going to tell the other actor to take damage that's it okay and then we're going to destroy our projectile so in order to tell the other actor to take damage if they understand it we have to we have to be able to communicate with the health system so that means we need to uh basically implement the blueprint interface for health underneath our class settings so that we know how to do that so in here we're just going to type in health we're going to tell our projectile that it also understands the health messaging system okay and then all we're going to do with our other actor is we're going to affect health and if and the amount let's go ahead and go 50 go ahead and compile and save and see what happens okay we got two problems well we have one problem one is our unfortunately our projectile is doing damage to ourself and I don't know if it's doing any damage to the enemy or if I'm just a terrible shot okay I think I think it's not even doing damage to the enemy so we're going to have to take a look at this so first problem to solve is when this projectile spawns it is actually um inside of our hero and so as it goes to the minute it shows up basically as a result of that it's overlapping and so then it will actually do damage and affect our health so what we want to do is let's put in here a little bit of an ignore remember back here in our hero top down character when we spawn or let's see here no no in our controller my my mistake in our controller we passed in the instigator as our controlled Pawn what I want to do is in our projectile if we check to see is this equal to and actually what I want is I want it not equal to let's see if we can do this yeah so we'll we'll we'll make a KN out of this in a second we want to check to see if this is equal to and let's get our instigator get the instigator okay so if the other actor remember we said not equal to so I'm going to do a not Boolean so not not equal to the instigator then it will affect the health otherwise it will just keep going okay so this should solve our self overlap problem however there's still a chance that we yep okay so we're good so we solved our health overlap problem which is great now all we need away is we need to figure out why our enemy is not taking damage so this sends a message message to affect Health our enem base does have a health component however it does not appear as though our enemy base is actually it does not appear as though our enemy base implements this do effect heal all we need to do is we need to implement the event so what we're going to do is just like it's the exact same thing we could copy it from our top down character we could literally just copy and paste this okay it's going to take it's going to basically take the amount feed it into into our health component and do damage so let's see what happens now oh that was fast I wonder what our default health is for our enemy let's add some health here we have default of 100 let's go 500 let's see what that looks like oh look at that okay now let's just double check one thing why is our enemy okay we'll have to figure out why our enemy is starting with uh so little Health on the health bar but overall let's see here begin oh I wonder oh I have an idea look at that okay so just like we had and let me explain to you what what we just saw in our enemy just like our projectile was overlapping our hero our enemy this box overlap event the one that's in the viewport that does damage to the hero that was actually overlapping ourselves as a result of it we were doing damage to oursel as an enemy like so the enemy was doing damage to itself because it was the this box is overlapping the capsule so we need to put a check in here to make sure the other actor is not equal to self oh actually this isn't going to work let's get a reference to self that not equal doesn't work self get self all right and we want to make sure that this is not true so let's put a knot in here okay so as long as that's not true it will do the damage it will send them message otherwise it won't so now if we play we should see our full health bar we do so now they take damage when we actually hit them and then they then they end up disappearing so y'all we are close we have a game we literally have a game we could we could actually t uh we can actually turn our enemy base back on to start seeking again and now all of a sudden I've got to chase I got to get him before he gets me there we go ah so cool very cool okay so at this point we've given ourselves the ability to add Health to any actor in our game we just drop a component in that's why we work modular and we added health bars for our enemies and our heroes even though we're going to be moving our enemy we created a projectile for our hero to be able to defend themselves now what I think that we should probably take a look at is adding some V effects to our projectile so that when our enemies die we get this nice popcorn explosion something rather than just blinking off the screen which would be great so let's go ahead and do that and do that welcome to intro to Niagara okay so to add some effects we're just going to start with the explosion we're not going to worry about the effects on the projectile right now so let's go ahead and create a new folder and this folder is going to be our VFX and in here we are going to create a new where are we effects Niagara emitter now the emitter that I would like to start with is let's start with the directional burst so we're going to create this and this is going to be the Niagara emitter NE and this is going to be let's call it let's call it death first okay and when we double click on this the way this is set up is uh you can see we have our burst it's kind of bursting out the back that actually might be kind of cool because it'll look like it's the the enemy kind of blasting out the back back the way Niagara is set up is you can see here this is our preview window in the middle this is where uh basically all of the all the information for the emitter is and then these are our details now the only thing I want to do right now is I want to change the color and let's just make this like 100 okay there we go maybe 200 that's great okay so now our burst is set to 200 and it it has a nice pop out the back so now all we need to do is let's compile and save this I am going to take this and I'm going to add I'm going to actually create a Niagara system now the Niagara system is going going to use what did we call that death burst we're going to use uh the death burst emitter now the reason we're doing this is explain a second niagar system death burst death let's call it death actually all right and I'm going to do that on purpose because here's what we've got have Niagara Works a little bit like a nonlinear editor so down here in the base you can see in the system we have death burst I could actually have many different emitters within the system and they can all do different things we can have one for the for the Sparks we can have one for the smoke we can have all kinds of stuff and you can edit them together all within this system and I'm just going to compile and save this and we are going to try to add this system to our character when they are destroyed so in our health component here we have our destroy actor if it's an enemy remember so let's just take this if it's an enemy and let's spawn system spawn system at uh spawn system at location okay and then what this is going to do is we're going to give it some information the system that we want to spawn is our the one we just created the death the um the Niagara system for for death and then the location we want to get is is we can just get the owner of this component uh did we not store the owner we didn't let's store the owner of the component up here so right when we begin play I'm going to get the owner and I am going to promote that to a variable and I'm going to call that the owner the reason I'm doing this is because we are probably going to be using this a lot okay and that is an actor which is great because from here now I can drag and I can get the owner and I can get the actor location I can feed that into the location and I can get the actor rotation rotation and I can feed that into the rotation now depending on how this particle set up if the rotation is aligned with the actor when the explosion happens it it may actually just go out the back we may have to adjust our particle let's just see what happens compile and save and we'll just go ahead and save all and now when we press play oh actually I was not ready okay let's let's change our enemy not to move okay uh this is our enemy I'm going to disconnect our move and I want to do another thing we need more than one enemy because we need to do some target practice here CU I want to see the different direction directions that this particle may go okay our enemies don't move now so let's start with this one so if I shoot it it goes out the front if I shoot this one goes out the front if I shoot this one out the front oh interesting and out the front Okay so we we kind of here let's do one other thing let's go okay I was a mistaken here's what's happening when we get our top- down character let's see here in our component Health all right what is happening is when we get our actor owner our owner is which way the pawn is facing it's not which way the projectile hit it from so we actually need a little bit more information and the information we need is we need to know what the direction of the hit was so let's let's add a variable to our let's see here we're in our health component we're going to affect the health and that is going to be see here part of our basically our projectile is going to call this inside of our enemy base so what we want to do is let's go revisit our blueprint interface for our health and what we want to say is the the messaging system for affecting Health a message not only can take an amount but we also want to take a Direction so let's take this and add a new variable and we're going to call this let's call this damage or let's call it impact normal just so we know exactly what it is and this is going to be a vector and then all we need to do is when our projectile which we don't currently have open when our projectile hits that's in gameplay when our projectile hits and we call the health what I want to do is I want to get the hit I want to get the I want to get the projectiles I want to get the actual projectiles Direction so let's get the velocity we can get that front let's try this we'll use the velocity get velocity get the velocity and I'm going to normalize that so that it is a direction normalize that and that is what we're going to feed into our impact normal okay so now that we have that in our enemy base when they get hit we just need to update our our actual uh event in the component for our health component so here we have our effect Health we need to add the same thing we only need one of them we need an impact normal impact normal normal means direction if you're new to this but it's basically a vector okay and what I want to do is I want to take this normal and this is what I want to use for the rotation so for vector or rot so let's make a rotator from X and that is what we're going to feed into the rotation now we have one more thing that we need to connect so that is our health component now has a variable in our enemy base we need to connect that to effect Health all right so recapping in our projectile base compile and save when it overlaps it is going to send the message to affect Health to the other actor if the other actor understands it what is going to happen is it is going to in the case of the enemy it is going to say I understand that and I'm going to call effect health for the health component and the health component is going to go ahead and do all the work to affect the health so with all that let's save all and let's see where we got to with our projectiles oh look at that it went the right direction let's see if that works oh perfect so now our enemies are basically getting wrecked is awesome they're getting wrecked and the direction is the direction that the projectile is traveling which is great so this is actually feeling really cool so far now all we need to do is one other thing we don't want our projectiles to keep going we want them to destroy themselves afterwards because unless they're piercing and then even then we want to maybe consider how long our projectiles are going to survive and let's let's talk about a couple things here so first off here is our begin overlap sphere we're going to do our effect health and then what we want to do is we want to destroy destroy the projectile and the actor is going to destroy itself in the frame of reference of the projectile base so that's cool so now we actually have a when it hits our enemy it will stop you can see that it doesn't keep going which is cool so this feels way better all right now I want to show you a problem and I'm I'm going to this could be tough to show you you see those projectiles see them off in the distance those projectiles are going to live forever that is not what we want they're still going okay so what we need to do is let's come back here and when what happens if how do we figure out when our projectile should destroy itself well wouldn't it be great if we could just set a timer and after say 5 Seconds the projectile just says oh it misfired we can do that so on begin play what we're going to do is we're going to do something called set timer and the cool thing is it pops up a name for us we're going to set timer by event and we're going to set our time to be 4 seconds for example and if that happens let's add an event we're going to add an event it's going to be a custom event and that custom event is going to be called event misfire and all this is going to do is it is going to destroy the actor destroy actor now remember the actor is going to destroy as itself and we're inside the the projectile blueprint the projectile is that self and in order to call this timer to call our misfire we connect these two red squares so let's connect that up all right so what's going to happen now is when the G Place starts for the projectile it's going to start a timer and after 5 Seconds it is going to destroy itself all right so let's see what happens if we shoot a bunch of these and inject let's see one two three four five look at that they all destroyed themselves and you can actually watch it too over here in our world outliner if I shoot you can see down here where all these projectiles have been spawned watch them start disappearing there it is after 4 seconds they all disappear 4 seconds is more than enough based on let's see how we're going to have to zoom our camera out depending on the size of our map but 1 1,000 to go I mean 1 1,000 2 1000 I'm guessing this is oh actually the size of this map that might be that might be the case I do think I want to zoom out the camera a little bit but anyways so let's not get distracted having fun playing our game it's actually pretty cool that it is now let's see what this is projectile base valid do effect Health hold on a second attempted access projectile base do effect Health we are in the enemy base we should probably check to see if when we do this if this is even a valid actor just just double check is valid let's see if we can get rid of that error message so if the other actor is valid compile and save press play we're just going to shoot a bunch of stuff I didn't see any errors that time that's great okay so our game is really starting look like a game I'm actually getting pretty excited about it but what we're going to do next is we are going to set it up so so that our enemies will spawn so we're going to create the idea of a spawner and what that is going to do is that is going to spawn a bunch of our enemies so that we can then move on to setting up how to win the win the game or clear the room so to speak so let's hop in and take a look at creating an enemy spawner to build this spawner what we are going to do hopefully you guessed it is we're going to make a blueprint so in our blueprint folder here I'm just going to right click and I'm going to create a BL print from class and this time what we are going to do is we are actually going to choose just plain actor and with this I'm actually going to call this our BP spawner base now we're going to do a couple of things with the spawner that is a little bit different than what we've done in some of our other tutorials so first things first what we need to do is we need to uh put our Spawner in our scene I'm just going to drop it uh back here actually this's just drop it right here that's good okay and then I also want to delete all of my enemies because this is what we're going to be spawning and I want to make sure it's working so here we go the way the spawn is going to work is when the game starts it is going to start a timer and the timer is going to every so many seconds spawn a random number of enemies within the radius of the spawner that's the plan so in order to do that what we're going to do is on our and oh we're also going to give this spawner we're also going to give the player the ability to destroy the spawner which is something we haven't done before either so this is going to be a lot of fun okay for so first let's start with the spawning the enemies okay so on begin play what we want to do is we want to set a timer so set a timer by event and for now let's just set this to every 3 seconds and what this does is this creates a timer that we can connect to any event we want and that event will fire every time the fire uh every time the timer requests it if you check looping so if you only set it once then what will happen is this will only go through one time but if we we click this looping button what you'll see is uh it will just keep on repeating itself over and over again so now that we have our timer what we need is we need an event to spawn our enemies so let's create an event I'm going to call this add event add custom event this is going to be event spawn enemy en [Music] enemies let's go ahead and take care of that okay so and then we're going to connect our timer to our event and just for demo let's go ahead and print string hello so when we start we won't see any hello 3 seconds in we'll see it print hello three more seconds in we'll see it print hello again so this is just going to print hello every 3 seconds but what we're going to do is let's just start by um spawn enemy or or uh spawn actor from class so what we want to do is we want to spawn a character and the class that we want to spawn is enemy this is our enemy base so that's who we're going to spawn and then we need to pick a location so a good location is some radius around our spawner so usually uh a good one that we can use is location in radius so get random location in navigable radius this is cool now when we get this location what's going to happen is it's going to we're going to take that and we're going to feed it into our transform but before we do that we have to set the radius so for now let's go with 250 let's say and then let's go ahead and take the origin Now where's the origin of this navigable radius it should be where the spawner is because we want the enemies to spawn around the spawner so let's get a reference to or we'll just get the actor location now remember the actor in this case is the spawner so self is referring to the frame of reference of the spawner and so this location is where the spawner is in our scene so this is going to get a random location within a navigable radius that that means that a character can walk on that is 250 units in radius all right and we're going to take that and we'll go ahead and we can just split this struct and we can plug this straight into our transform now when we do this if everything's working right when we go ahead and press play we should see is when 3 seconds we have an enemy which is cool now you'll notice oh three more seconds we got another enemy so our spawner is already working it's finding spots within navigable radius and spawning enemies every 3 seconds which is great now why aren't our enemies moving okay so generally there's two pretty common reasons enemies don't move one is the nav mesh however you've seen enemies move before but it is a good time to point out that this project is a little different than some of our previous the nav mesh is already built for us you can see it over here on the right in our nav mesh bounds if we press the P key in our level it will show us all the places an enemy can go now the reason I wanted to point this out was I wanted to make sure there wasn't something about our spawner or where they were spawning that was possibly causing them not to navigate so that's one but that's not actually actually the reason why our enemies are not moving if we go back to our enemies and we scroll down in and we look at our AI let's try typing possess here okay so notice here under Pawn we have an autop possess AI option now even though we don't know it this simple move to that we do on our enemies that simple move to is using AI to do that so what we're going to do is you'll notice that when we do that right now it's on placed in world we need to change this to spawn cuz we're no longer hand placing these in the world we're spawning them instead so let's just compile and save that and give that a shot see if they start chasing me now nope we're still missing something so let's make a couple updates here oh we actually uh the thing that we were missing is we forgot to reconnect our simple move to actor okay so if we reconnect that hopefully then that's the trick nope yes we do oh my goodness in there so fast that is ridiculous okay now the one thing I did want to check was I I just wanted to double check show you all if we go back to our class defaults for the pawn see if I can find it without all right let's just do the possess again if we switch this possess to placed in world let's see if this still works I've had this not work before yep so that does confirm it placing in because we had the setting set to place in World it didn't we needed to change that to spawn instead okay so really what it was was we just had disconnected this for testing purposes okay so now our spawner is actually spawning our enemies and we can we actually are starting to get to a point where we have a game except they're so fast I can't get away so now that there spawning what I want to do is I actually want to change how many of them spawn so remember we had said let's go ahead and randomize how many spawn and then let's also make our enemies a little bit easier for us to destroy so I'm going to knock while I'm here I'm going to knock their health down uh let's see here health component default value let's try uh 250 for example okay and then let's go back to our spawner CU this is all about the spawner so every 3 seconds we're spawning enemy well what if we wanted to spawn more than one enemy so here's what we're going to do we are going to create a for Loop in here so let's go four and I'm going to use a regular for Loop because this one works with numbers so if you don't know what a for Loop is we have a whole series on for loops and arrays but basically what this is is this is going to repeat something so many times in this particular case what what I want to do is I want to get a random number of times and the random integer in range that I want to use is let's say we can spawn between zero and maybe five enemies that might be intense five of these characters run around okay so what's going to happen now is the game's going to start then the timer is going to start 3 seconds later it's going to spawn enemies every 3 seconds it's going to spawn enemies it's going to get a random number between 0 and five and that many times is is for for each 0 1 2 3 4 5 it goes through finds a random location around our spawner and spawns an enemy so let's see what that looks like first time was one enemy two enemies oh wait they're actually killing each other oh I didn't even see that okay that's awesome Friendly Fire okay that's working so we're we're getting more than one enemy which is great so this is definitely working now the one thing that is happening is they are they're they're instantly appearing at the same time so what we could do is we could possibly try something like to put a delay in here however the problem with the delay is sometimes for Loops don't work with delays but let's just try one it and see see if we can actually show you the example delay of let's go .5 so it's very obvious it's happening so we're only ever getting one I know it seemed like a while that I was thinking but we're basically only ever getting one enemy the reason for that there's no way the odds are against us with this kind of for Loop so this delay what's happening is it comes in here it tries to do this for Loop and it does it within a single tick and so what ends up happening is it does the first one but we never come out we never finish our DeLay So if we want to stagger our spawn what we could do is we could create a new function that is or a new timer that staggers our spawn for example so there's there's a couple different ways we can do this but let's just go ahead and do this let's create okay so we have our timer by event and this is going to fire every 3 seconds and then what we could do is we could create another timer by event let's do this timer by event getting wild but the repetition will be good so let's just take all of this and move it down okay I'm going to disconnect this and then what I'm going to do is I'm going to set this timer to be 0 3 three is one tick so let's just say we want to split them up by a tick each this also is good because then we're not spawning all of them at the same time so the game is not loading them so let's add a new event this event is going to be event stack event stagger spawn okay so this is going to trigger repeatedly every tick basically every .003 seconds now this is where we need to change how or the number of enemies to spawn what we want to do is we want this to be uh basically a value that we can tick down okay so here's what I mean let's set this to let's let's set this to a variable so we're going to promote this to a variable and we're not going to call it last index we're going to call it num enemies to spawn all right and then what we're going to do is we are going to get a random integer in range between 0 and five and then we're going to set our number of enemies to spawn now we're we're going to be getting rid of our for loop as well but uh before we do that let's just walk through this so now we have a random integer between zero and five all right and actually I'm going to bump this up 3 to five so it's going to spawn 3 to five then it's going to set this timer that's going to start ticking based basically it's not a tick it's a timer every frame we could also put this on tick by the way um but just for kicks let's just keep going here so then what we're going to do is we're going to set timer by event and we're going to start spawning now what we want to do is we want to let me move this for Loop out of the way let's get the location or get the random point and then we'll spawn the actor and then I want to take the numb enemies to spawn and I want to decrease it I believe we can just do a minus minus on this yeah we can just decrement this okay so decrementing is just the same thing as subtracting one so what this is going to do the first time through let's say we had three enemies it's going to come through event stagger is going to get a random location and it's going to spawn an enemy and then it's going to take number of enemies and set it to two then it's the second time through it's going to come through it's going to set it to one and then to zero so what we need to do is we need to put one more check in here so let's get our number of enemies to spawn and let's check to see if it's greater than zero if it's greater than zero we will do all this so we can basically get rid of our for Loop and I'm going to hold the b key to get this to pop up B for branch so if it's greater than zero then it is going to spawn now this particular I setup it's important to understand there there's more there many ways to do the same thing in unreal a lot of it is going to be based on your project what you're doing Etc so like I said we could use tick since we're doing every tick but maybe you know maybe we we set that out to stagger it even more so in the first second we should get there you go you saw them kind of pop up all right so this time let's make it even more pronounced let's go 0.0099 so that should be three frames between so let's just see what that looks like there we go that looks good right that even that feels good I think that's a much better spawn right cuz they come in a little bit offset that feels really good what a happy accent um I'm just double checking if there's anything else I want to do okay cool so what we now have is we have our spawner comes in 03 what I would like to do is I would like to make this a variable that I control so let's do this let's take this max number of enemies and let's right click and I'm going to promote this to a variable and I'm going to call this Max enemies and I want to make this instance edible and expose on spawn the reason I'm doing that is because what I want to be able to do is I want to be able to have more than one spawner so let's just say we have this spawner over here right now if we look at the default you can see here I can now set max enemies which is great so now I don't have to go back to the blueprint to make changes so if I set my Max enemies to one now I can move or make a duplicate I'm going to alt drag to make a duplicate of this spawner I'll put it over here in the pillars and I'm going to change my ma Max enemies over here to five now what that's going to do is I should get one every now and then from here and a many more enemies coming at me from the right on this one so that is why we exposed that variable to uh instance edible Expos on spawn so let's just see there we go we had four enemies come at us from the right oh I managed to survive that one from the left so this way I can set up I can now spread these spawners all over and I can control how many these are how many enemies are spawning Etc which is great now we can do a couple more things in the same vein let's do uh let's change our oh this is not the spaw okay here we are in our spawner let's change our spawn interval for our enemies so promote this to a variable and I'm going to rename this to spawn delay spawn delay so that's another good variable that we could use and that's comp uh instance edible and exposed on spawn so now we can have enemies that spawn or a we can have a spawner that goes faster or slower now one thing to mention this spawn delay that we're using right now or this stagger this is our stagger timer it's important to understand this stagger timer is if you spawn 100 enemies and it takes 0.1 seconds between enemies what you end up with is 10 seconds right 10 you end up with 10 what you want to make sure is you got to make sure your spawn delay is less than your your setting your timer by event because otherwise what ends up happening is uh you'll get you just keep stacking these things so there we go now the other thing that I want to do here is so now we have a spawn delay which is great now the other thing I want to do speaking of cleanup is when we begin play this is our overall timer for spawning enemies this will get destroyed when we destroy our spawner when we come down here to spawn enemies though every time we trigger this every 3 seconds it's going to start a new timer okay now fortunately that timer is going to be very fast but when the timer is done right now we're not destroying the timer so let's go ahead and Destroy This timer so I'm going to right click and I'm going to promote this to a variable and I want to rename this to be stagger timer handle and the reason we've done that is because when we're done if it's greater than zero we're going to spawn but when we're done if it's not what I want to do is I want to clear and invalidate the timer handle now now technically we might be able to reuse it but just for ease right now let's just go ahead and clear it so this way we're cleaning up this timer that we're creating every right now every three frames is basically what it it's approximately it's approximate Okay so we've got some variables we've um we've cleaned up our spawn timers let's just go ahead and double check and make sure we're good yep everybody's still spawning oh they're getting close all right don't get lost all right so that's looking really good so now we need a way to destroy our spawner now the cool thing about it is our spawner is an actor which means we can put components on it one of the components that we've made if you recall is a health component so we can actually add Health to our spawner now we're going to need a couple other things with the Spawner in order to be able to know where it is we're going to need a visual we're going to need to be able to hit it there's a bunch of stuff in order to do damage and destroy it but we definitely need health so by default our spawner is going to start with uh 100 health and then what we want to do with that is add a visual now so that we can find it we're going to keep this easy let's go ahead and add a static mesh and the static mesh that we are going to choose is going to be something fun let's say let's do a chair we're going to spawn our enemies out of a chair for example okay let's double check and see how big it is there's our chair all right great now here's the thing though we need to make a couple changes to the static mesh because the static mesh also has Collision see how it has all block all Dynamic and everything on it this could cause problems with our enemies let's just see what happens actually nope they're good actually it's probably good that we keep that mesh there all right so we'll just keep that um the the thing I was going to say though is if you add Collision for example you probably will need to change these values so what you can do for example let's actually let's just go ahead and do it let's add a collision going to put a box Collision in here and the reason I'm doing this is because we're probably going to use this to help us with the damage so let's just do this like that for example now then what we can do with our static and I'm going to reparent this to the scene route and then for the static mesh I'm just going to not generate overlaps we're not going to step up on and I'm going to do no collision and then for the Box what we will do for our Collision is can character Step Up on no generate overlap is fine overlap all Dynamic that sounds great all right now what I'm curious about is can we actually shoot yep so our projectiles are hitting the spawner they don't do damage yet and that's because we haven't connected anything to tell our spawner to do damage or receive damage so what we need to do is we need to tell our spawner how to listen for the messages that are coming as part of the blueprint interface for health remember how we did that in our class settings we implemented or added an interface in this case we're going to call Health and when we do that we get our interfaces over here on the left and in our event graph we can actually now Implement do effect health so let's implement this event and if you recall since we have all of this already done all we have to do is affect heal and then we can and feed in the amount and the impact normal and this should affect the health of our chair now if we hit which is in a chair it's our spawner but if we hit our spawner twice now we should be able to destroy it nope not yet so let's do a couple things let's figure out what is going on we're definitely hitting it let's see we come in here we are affecting health health component that all looks connected my guess is there's something about our collisions okay I think I figured out what it is um everything we're doing here is fine all of our settings for all of our Collision are fine but look let's take a look at our health component here for a second okay our health component if you recall when we built it we basically set it up so that on begin play it checks to see if it's an enemy and if it's an enemy then it sets it as true and then it checks to see if it's a character and if it if it is it gets a controller cast the controller and sets the player and if it's not an enemy which it's not it cast a character and then it if it succeeds it gives a player controller but what if it's a spawner so I think what we actually we're going to have to get a little smarter about how we're doing this what we could do for the purpose of just moving forward right now is if this fails we could actually take this and we could check to see if it we could cast it to a spawner for example spawner base and if that's the case then what we can do is we can set is enemy to true and what that will do is now down below actually let me make some room here when we go through our effect Health function and we get to the is enemy part what will do it will go straight to true all right whereas before it wasn't an enemy and it wasn't a player so it would come down here it would fail and then it would do nothing all right so we just need to make a quick change in here so let's go ahead and set enemy to true and there's another way we could do this actually but for now we'll just keep it like this because I think it's a lot simpler to understand but you can see you don't want to sit here and Nest all of these right we want to find probably a better way to do that in the future so for now let's just go and see if we can destroy our chairs oh there goes the chair and we got it we just won our game a it okay so let's see where we are with our spawners we can in our scene we can set it up so that on each spawner we can determine the max enemies the spawn delay everything like that we oh we should add a health bar that's what we need we need a health bar so for our spawners what we're going to do is we're going to add a widget just like we've done before and this widget is going to be in screen space and we can leave all that stuff there and then on begin play in addition to our timer we are also going to create a widget and the widget we're going to create is a health bar and we're going to give it the health component you can see how we're reusing all this we're getting a lot of this stuff super fast and free just because we've created these these components and widgets and all kinds of stuff which is fun okay so then then what we're going to do is we're going to set widget and that is going to set our widget for this to be the widget that we populated and let's just see where this is in our viewport if we pick our widget right now it's below the chair let's just move it above the chair compile and save let's actually save everything and we'll go ahead and click on play now our chair now has Health look at that our chair has Health our spawner I should say our I guess I already killed yep I already destroyed I already destroyed the other one and I just won the game again so now if we just want to have one last fun deal we can actually take these we can spawn them from all sides our game's really starting to shape up okay so they can come at us from any direction oh didn't even make it didn't even make it okay don't want to get too lost but you can see how what's happening uh we're good to go so we very quickly took our spawner we've we've got it spawning enemies they even stagger spawning and it has a health bar we can destroy it that can be part of how we clear levels maybe that's going to be the condition all enemies are are dead and all spawners are destroyed and then you can actually leave the level who knows we'll figure it out as we go now there is one other problem that I want to address before we move on to the next section and what that is is if you notice our enemies are not firing a single projectile and when our enemies hit each other they're doing damage to each other they're literally running into each other and doing damage we don't want our enemies to do damage to each other so on our enemies if you recall this box is the one that's doing the damage and on our event graph if we do the overlap we check to see if the other actor is valid we check to make sure it's not ourselves but what we should also do is let's in this case check to make sure that it's not an enemy so what we can do is we can get the class get the class and what we can do is we can check to see that it's not let's see if we can do not equal yes we can do not equal to Enemy enemy base all right now why this is cool is because then what we can say is if it's not our s and it's not an enemy by we and we use the Ampersand and here so or you can type in and we get the and then affect health so now what should happen is we should let's clean up our Neals here just a little bit we should actually be able to see that our enemies are not if I can survive long enough we should be able to see that enemies are no longer damaging each other they're not looks good holy smokes looks good I just got wrecked again so we got it we got uh are we got our spawners working they have health and everything this game is almost there but that does mean we need a way to win this game so to do that let's take a look at our game mode now we need to set up some of our win conditions and uh our lose conditions before we get into the UI to show it all so our game mode as you've probably guessed is a different kind of blueprint now the interesting thing about the game mode for the top down shooter is unlike if you follow our horde mode mini game we don't need to create it from scratch the reason being is the top down shooter already has a game mode created for us so if we take a look in our blueprints folder under top down you'll notice in here we have a top down game mode now this game mode is actually currently being used in our level settings over here usually you're looking at the details but if you click on world settings you can see this is being used as the game mode override so that's how we know we're using that game mode and that's what's actually being um set up when we when we start and use our game now if we double click on this if you come in here you may see just a single screen that shows just the details if that is the case and this just kind of depends on your settings you may have to click the little blue uh text that says open full blueprint Editor to get a view like this we're going to want this because we're going to be making some changes to uh what our game mode has associated with it variables and things like that but over here on the right we have all the classes that are associated with our game mode session the state base the controller the player State the HUD which we're going to be changing later etc etc now what we want to do for the game mode is we want to control all of the win conditions keep track of the score figure out when a levels complete all those kinds of things for our game so to do that we need a couple variables here are some variables that I would like to add one let's create a score this is going to be an integer and two I would like to create one called number of spawners because what we're going to do is we are going to set it up so that when a spawner gets created it registers itself with the game mode what I mean by that is when a spawner starts it is going to tell the game mode hey I just started the game mode is going to say o I have one spawner then the second spawner is going to come along and it's going to say I am spawning then the game mode is going to say o I now have two then as the player destroys the spawners when we get down to zero that should end the level and win the level that's what we're shooting for so to do that we need to keep track of the number of spawners and what we want to do is let's create an event I'm going to add a new custom event and I'm going to call this event increment spawner count okay and all we're going to do when we come in here is we're going to take our number of spawners and we're just going to do Plus+ now this is the same exact thing this Plus+ just so you know literally is the exact same thing as taking this spawner and adding one to it not 11 one all right but this is just a quick way because it's such a common thing that we do uh we uh we have an increment now interestingly enough we also have a decrement which does the opposite it subtracts one so let's take this let's add a new custom event and this one we're going to call whenever a spawner gets destroyed so we're going to call this decrement spawner count what we're going to do in here is we're going to take our number of spawners and we're going to minus minus decrement int now the other thing that we want to do in here is we want to if the number of spawners is less than or equal to zero you win so right after this we're going to go ahead and say less than or equal to zero and if this is true let's go ahead and print a string saying U1 U win now eventually we're going to connect this to an entire Victory and defeat UI Etc but for now this will this will tell us that this is working okay so we have our game mode that's great it increments and decrements spawners which is awesome we'll get to score and stuff like that here in a second now what we need to do is we need to update our spawners to tell the game mode that this is all happening so to do that what we could do one thing we can do is we can go into our spawner base and on begin play what we're going to do is we're going to get the game mode Let's get the game mode and with the game mode there we have a couple options we could just cast this to a game a top down game mode and by doing that we can now call the event uh increment increment spawner account now the reason we have to cast this is because not all game modes have this spawner count I have to make sure it is a top down game mode so if I tried to drag off of just the game mode and type increment nothing shows up we have to make sure it is a a uh top down game mode first now before we do this though I'm going to go ahead and promote this to variable because we're going to be using this and I don't want to do the cast every single time so here's what we'll do do let's disconnect this reconnect this everything's connected and I'm going to change this to just game mode for now and there we go so now when we begin play with our spawner we're going to get our game mode if it's valid and we can cast to it it's a top down game mode we're going to set a variable and then we're going to increment our spawn count so in our current level we have four spawners now we also need the flip side we need to be able to in our spawners when they get destroyed we need to tell the game mode that they got destroyed so let's go ahead and go down here and here we are we're affecting the health and let's see here we could basically just say after we affect the health this is going to get destroyed ah let's see if there's a at event I believe there's a destroy actor event yes we're going to do this so when our actor gets destroyed what we're going to do is we're going to get our game mode and we are going to decrement the spawner count and there you have it so what should happen is our health our effect health is going to go through do what it normally does and then when it destroys the actor this will actually get called and it will decrement our spawner count theoretically so let's give this a shot and we're going to have to do a good job so that's one spawner oh there okay I'm I am way too slow at shooting so actually can I just hold it down now oh we didn't do that we should do that yeah our game's too hard I can't do this so I'm going to change it so all of our spawners spawn let's do this let's go how many enemies do these spawners spawn on our details I'm going to change our Max enemies to one on all of these so let's just take all of these to Max enemies One Max enemies one one and one okay now we can try again what we're trying to do is we're trying to destroy the spawners so that we can check to see if we wanton our game all right now we should see after we destroy this one there you go you see it print in the top left it printed you win which is awesome so that actually that actually totally works that's great so that's going to be our wi condition and that's what we needed in order to build our UI now while we're in here since we're working with the game mode Let's go ahead and do the exact same thing but this time for score because we need to keep track of our score so here's what we're going to do we are going to add a new event event add a event this is going to be custom event we're going to call this event um what should we call this score adjust score effects let's call it effect score for example and we're going to take this event is going to take one input and we will take it as a score or or let's just say amount maybe amount and then we will make this an integer okay and then what we'll do is when we come in here we're going to take our score the current score and we are going to add to it a value now realistically speaking why would we reduce the player score the only types of games I can think of that you might do that in is for example if you're doing a shoot them up and there are civilians in it or something like that and you accidentally hit one of the friendly targets then maybe your score goes down all kind but either way the point is if amount is positive your score is going to go up if it's negative your score is going to go down so then what we're going to do is we're going to set our score to be the result of that so then all we need to do is the exact same thing in our enemy if we go to our enemy base and we want to or actually we can affect our score with their spawners too so let's say enemies first we need to uh get we'll start with the enemies first we need to get our game mode in here let's get the game mode get the game mode and then we're going to cast this to a top down game mode if it is successful we will promote this to a variable we'll set it and then we that's all we need okay so let's just change this to Game Mode okay so then what we want to do is we want to whenever we affect Health let's do the same thing again here we're going to add into the event destroyed add destroyed we're going to take the game mode and we are going to adjust or let's do score we're going to affect the score now this is where we get a little bit interesting so we want to affect the score by a certain value let's just say that enemies are worth 100 for example and then what we could do in our spawner we could also adjust the score or affect the score and what we're going to do here is maybe spawners are worth more maybe spawners are worth 200 now you can really pump up your score by letting more enemies spawn for example so let's move this up aot line these pressing the q key so now we should be incrementing our score we don't have any way to display it yet because we don't have a UI so what we'll do is in our game mode anytime we affect the score let's just go ahead and print the current score just so we can see it happening we'll keep our wi condition there compile and save and let's test it all out but first we're going to save all okay so 200 400 okay our enemies are not our enemies oh yeah they are 600 let's just double check we should get 100 for enemies a random number of spawns is there we go 800 you win oh wait a second I didn't get to see that let's try that again all right I didn't see that one print Did you nope I didn't see that one print either we need to run that again you know what let's just double check that we're hitting that with our enemies it's possible that our enemies are getting destroyed wait where is our enemies oh we put this in the wrong we put this in the wrong place okay so uh we put this in our top down character which is ourselves we don't want to get points for for ourselves uh we'll keep this game mode in here we may need it for our top down character but we do want to actually put this in our enemy so we're going to do this one more time and in our destroy let's see here begin play Let's get the game mode get the game mode cast it to top down go ahead and with that promote that to variable and then we'll go ahead and make that uh game mode now with that just like we did before and we're going to add an event for destroy did I just copy and paste that ah here it is okay so now let's get destroyed where's our event destroyed go ahead and set that here all right one more test here we go get this first spawner that should be 200 300 500 there we go now it's working and we don't get points for getting wrecked ourselves we wait for one more just to double check it all right I believe so we can oh we got a runtime eror game mode event effect score ah interesting okay so let's go ahead we do need to maybe put in here a check let's just make sure the game Mode's valid so not is valid I'm going to use valid uh this usually happens if your game ends and it's still cleaning up for example uh it triy you've destroyed everything in the scene but it's still uh as it gets destroyed it tries to affect the game mode but the game is ended so it gets there's some stuff like that so we may want to do the same type of thing in our spawners although our spawner spawn base let's go ahead and double check before we do all of this if our game mode is valid little bit of noodle clean up and then let's go valid just to be sure all right so if all these things are true we should be good to go let's go one more run this guy's G to get me kill that one all right no more errors perfect Okay so we've set up our game mode we have our score we have uh we have the ability to uh win the game we're not going to do the UI well we are going to do a little bit of UI first but the first UI that we're going to do is I thought it would be cool to do a one form of damage numbers as part of this little mini game game so what we're going to actually do is we're going to add it so that when we shoot an enemy the damage numbers pop up and the way we're going to do that is in with our health bar now there's a lot of different ways to do damage numbers I think that this one is probably a great one to help wrap your head around so here's our health bar and when I when I say there's other ways you could do it you can do it with a um particles for example you can do it with um you know individual widgets the problem with the particles ones it's not a problem it's just it is a it's a deep Rabbit Hole so this is a cool way to do it and it'll teach us a bunch of stuff about UI so here's what we're going to do in our canvas panel we're going to go ahead and we are going to add an extra text and this text what we are going to do is we are going to default it to zeros let's go uh sure I don't think this size Matters let's go ahead and set our anchors though to be the middle and then we need to get all of our offsetting and then the text also needs to be Center AL line now we still have there we go okay so our text is now in the middle uh I believe we probably have all of our anchors are good okay great so here's what we're going to do here's our damage numbers we are if you look down in the bottom usually it's on the bottom of the designer or there's a button here on the left you can click on your text or and there's a tab for animations so what we want to do is we want to add an animation because what we want to do is when we show damage numbers we want the damage number to kind of pop out of the enemy's head so let's add an animation and it's going to be the uh damage numbers right when we click on this we're going to add a track and the track that we're going to add is I think oh we need to I'm going to go ahead and make these damage numbers a variable these are going to be text damage amount okay and what we're going to do with the damage amount is we are going to add a track for the text damage amount but not the text yep the text and then in here we're going to add a track for two different things we're going to do one for the transform give me a second to find it and then we're going to do one for the color and opacity all right so let's start with the transform the way animation Works in this UI is this is our timeline goes back and forth we're starting at frame zero we need to set uh key frames at frame zero these are where it starts okay and then we need to go forward some amount of time let's go 1 second for example and and all we're going to do is we're going to animate this transform so let's just animate this upwards for example okay now when we do that I'm going to this is probably set to single I'm going to set this to looping and press play so you can see our damage numbers are now going upwards all right now we can make this a little more interesting by adding in an extra key frame here where what we can do is we can take the 75 Mark and middle drag it back and set a key for frame on our y value and what that's going to do is that's going to give it a little bit more of a pop effect right it's going to it's going to rush up a little faster and what we could do is we could make this even more extreme so it gets a a nice like kind of drift to the top go even more actually okay and then overall I think we're going to need to shorten this Okay cool so now that we have that let's go ahead and go here cool that feels good now what we also want to do is maybe we also change our opacity so we're going to start 100% Alpha so let's just stop playing so we can actually do this we're going to start with our Alpha is the transparency if you're not familiar with colors there red green blue and alpha alpha is how transparent is so if we set a key frame on our Alpha what I want to do is we're going to keep it at 1 to about here so I'm going to set another key frame by clicking this button and then by the end I want it to fade out completely so let's drop this to zero so now what should happen is you'll see it kind of Fade Out now that's a little bit little bit harsh so let's see if we can smooth that out I think that feels good okay now what we'll do so here's what we need to do now that we have this animation created let's compile and save we need to do a couple of a couple more things we need the ability to trigger the animation we need we need to be able to tell the system hey play this animation whenever damage is done so what we want to do is we're going to add a couple events here one well even before we we add some events what I'd like to do is I would like to yeah let's do let's add a new event this one's going to be custom event this is going to be event show damage me zoom in a little bit so you can see this and then what we'll do with this show damage is we're going to do a couple things we want to give this an input and we're going to the input's going to be damage amount and this is going to be an integer and we're going to take this damage amount and we're going to change our damage text so with our text damage amount we are going to set the text to be this value so this is going to automatically convert it this is the text is text the damage amount is an integer so what we're going to do is we're going to go ahead and set that now once we do that now we now we can actually call set damage amount so let's compile and save that and I don't think we're going to see all right yes we do see we do see the numbers above our head we're going to change that so we don't see those in a second but at least they're showing up that's great so we get that for free now what we do need to do though is we need to in our health component let's see is this where we want to do this let's do this in our enemy base actually when we affect the health this is where we are going to trigger the damage amount so to do that what we want to do is on begin play we create this widget we set this widget I want to set a variable so I have access to this health uh bar widget so let's promote this to a variable and this is going to be our health bar widget uh let's call this health bar widget for example that way down here after we affect Health what I can do is I can take the health bar widget and I can run an event show damage so here's what's going to happen we're going and this this float is going to get converted to an INT so now when we actually do affect the health we're going to see the damage numbers changing they're not going to animate yet we're going to do that here in a second so see how it's see how it's changing so now it's minus 50 for now we know we're changing the numbers now all we need to do is we need to trigger our animation at the same time so what we can do is we can take this damage numbers animation which is underneath our animations now and we can I believe it's play from let's see here play forward cool so if we do damage we're going to go ahead and play the animation now we are so close okay where's our enemies look at that look at that oh did you see that that was cool okay now every time we hit them we're getting a damage number now the damage number is going a little bit High because it's because of our perspective so what we can do is we can come back to our animation in our designer and we can adjust this so this this height that this is traveling to is a little bit too much so if we take a look at our translation y value you can see where it's getting to the the problem is if I affect just this one piece really what I want to do is I want to affect the curve so you can click this curve editor and if you look at this we look at our transform our translations you'll notice that this is our translation curve I'm going to take both these values and I'm just going to move them uh up let's say let's just go let's try half okay so that way I can adjust both keys at the same time let's see what that looks like in here oh wait I did not mean to click that play I meant to click this play that still feels good okay let's see what that looks like in the viewport though because we kind of want them to stay on screen oh yeah that's good we could probably go a little bit less but that's good so you can see we have our damage numbers playing so here's what we need to do there's a couple more bits that we need to do if we take and we need we don't want to see the numbers when we start we only want to see the numbers when the damage is actually shown so when we start on our construct let's see here invent construct what we can do is we can take this text damage amount and we can set the color and opacity and what we're going to do is we're going to set the opacity to so let's make this so let's make one of these make a slate color okay and the color that we're going to use is going to be we can keep it uh let's do red we can do red sure and then for the alpha let's go zero okay so what's going to happen is when our health bars are constructed it's going to set the default value for the text to be should be red and also invisible so we should not see any text when we start but when we do damage let's see here here we go now we got it now they're not red though that's interesting so are we setting our oh are we setting our color value as part of our designer uh yes we are so we're setting our color and opacity for our our um for our damage numbers here so if we were to change this if we go back to the beginning and we want red we can go Z 0 like so so now we'll get red numbers so those were effectively overriding what we had now we're not getting our damage numbers on our spawners right now there we go honestly the Red's a little bit hard to see but it's it's fine let's not delor that point that all works I would actually probably take this transform a little bit lower still seems kind of a lot compile and save that and let's do the exact same thing for our spawners super easy to do when we affect our health all we're going to do is do damage uh let's see here not our health component what we need to do is up here when we begin play before we set the widget we need to do a similar thing what we want to do is we want to promote that to our variable and this we called what did we call that in our enemy we called that health bar widget just be consistent here health bar widget health bar widget now this could be a good thing that we would potentially want to just put in as a component or part of our component so that we're not redoing this work everywhere we want to but for now it's good repetition so we have our health bar widget so all we need to do with that health bar widget we'll get that and we will go ahead and we will damage we'll show our damage so now when we do damage to our spawners they will also show the damage compile and save that and we should be in a good place there we go interesting I think because of the location nope oh they're still there I think it's just hard to see that when they're red so okay we got a lot done so far so our game is close we have all the pieces we need to win we even have a U Win option but what we really need to do to kind of put a bow on this whole thing is we need a little bit of UI work so it would be great if we could show our score our health bar a victory defeat a pause screen and we can restart our game so with that we're going to be doing a bunch of UI work so let's hop in and check out a HUD so to create our UI as before we're going to be actually doing two things we're going to be working with widgets and we're going to be working with Huds so let's start by giving ourselves a a HUD so if we right click and we do new blueprint class we can go ahead and we can choose uh we can type all classes we can type in here HUD and we're just going to select HUD I'm going to select this and I'm going to call this HUD and this is going to be our twin stick shooter um yeah we'll just call it HUD TSS twin stick shooter okay now that we have our HUD if we open this up what we're eventually going to do let me bring this over here what we're eventually going to do is in the event graph on begin play we're just going to spawn our um we're going to create our WID and add it to the vport so that means we need a widget so let's go back and we're going to create a widget kind of like we did before with our health bars but in this case let's just go ahead and BR this over create a user widget we're going to call this uh widget blueprint TSS HUD okay now in our HUD once again remember what we need in in our widget I'm just going to call it the widget from now just for clarity so in our in our widget what we need if you recall is we need a layout or they're usually called panels to work with these are all our panels canvas grids Etc we're just going to reuse the canvas panel and we need a couple things let's put a score in the top right so that means we need some text and for now we can just drop this into the canvas okay and with our text what we're going to do is let's see if we can make adjust our ink ERS so that it's basically the entire top of the board which is coal and then if we change our offset right to nothing and we do Zer uh zero and then zero well keep pressing Arrow key okay so now this stretches the whole length of the top of our window which is great and all we need to do is we need to get our text to align we're going to want it to align to the right side so let's see if we can do this by font color outline settings I feel like I'm missing my font alignment here it is right there we go down here down here when we get back to Shadow brush Etc we can get our justification okay so now our score is always going to be in the top right I'm going to change this to a bunch of zeros just to start with so we have it and I do actually want a little bit of padding so let's give ourselves there I don't see padding in here so we may need to wrap this to get our padding yeah we don't have that so let's see if we can do a quick wrap on this we may undo this so let's wrap this with a border and here's our border our border does have padding which is great so let's give ourselves a padding at the top from 50 and from the right of 50 so our score is going to be kind of slightly offset so there's room to read it we can adjust our our font size and everything like that later so that gives us our scoreboard and we can actually label this let's label this so we know is this is going to be our text score and I am going to make this a variable okay so we got our score now let's add our hero health bar to the bottom here and we're going to do that once again with a progress bar we're going to set this just like we did our previous progress bar and this one we are going to drop down we're going to try anchors at first so let's go bottom of the screen and then let's kill all of our offsets so now our our our our health bar is spanning the entire width of the screen that's not quite oops that's not quite what we want okay um we have size y That's great and let's see see if we can maybe consolidate this down a little bit what I'm going to do is I'm actually going to wrap this with a I'm thinking horizontal box because I'm thinking about dividing the Hut up into three sections either a left padding a right padding or what we could do is we could just wrap this with the Border as well and in our border we can change our padding or now that we have our border we can change the padding on our progress bar to say 100 uh maybe 500 and let's go 500 on the right so our our progress bar is now going to scale to the size and I want to change uh the content and color opacity of our border I don't even want it visible uh wait a second it looks like our border is coming through so let's try replacing this with rather than a border let's just use an overlay instead and with this overlay we'll fill just like we did before and we'll put in a padding of 500 there we go that's what we want and we'll do 500 not on the bottom that's going to be weird we do 500 on the right okay so that's good and then we should probably replace this border just in case with an overlay as well and we're going to have to once again with this we'll go ahead and fill so that it all lines up properly okay so what that should do is that should anchor you can see as I resize my window now it all scales appropriately which is kind of what I was trying to get to so now we have our health bar we need to do a little bit we're going to call this let's rename this this is going to be our progress bar Health U hero health for example we could just call it health and it is a variable that's good and let's go ahead and change change our progress so left to right we're going to go halfway so this blue is our health we want to reset this to a nice bright green uh just for clarity and then we would like to reset our background somewhere in here is the background color border padding fill color and capacity let's see if we can just type it in maybe it is actually white let's see if we change this yep that's it that was tricky okay so I think that's a pretty harsh red so I'm going to go for something like this okay so now we have our health bar we have our scoreboard we just need to connect them up now interestingly enough our scoreboard no longer has the padding from the corner so let's offset 50 let's do so what I want or do I want to do with the padding I'm going to do with the padding let's go back and change this off to zero let's change the padding on our text to be 50 yeah there we go I don't know how we lost our padding maybe when we swapped our boxes but there we go let's compile and save this and then what we need to do is we need to do the same type of thing that we did before where on basically on our pre what we want to do is we want to get the player and then or no we want to get the game mode so let's do this let's get the game mode get the game mode get the game mode so here's our game mode on construct and what I'm going to do is I'm going to promote this to variable just so we have it I'm going to name this the game mode and now that we have our game mode we can use that this uh to kind of set up all of our values by creating a bunch of bindings so let's go ahead and do that I don't we may have been able to do that even without getting that but I like to have it for later just in case so back in our designer for this text for the score what we are going to do is we're going to click on this bind button and see if in our game mode our game mode only has an option string so let's just create a binding here so let's get the game mode get game mode and from there let's get our score maybe we don't have a score enter game mode yet yet let's go back projectile base blueprints here's our top down game mode and let's see here we do have a score ah but we forgot to cast it so let's go back to our widget and what we're going to do is we're going to change this game mode to be a TSS game mode uh but we didn't call it that it's actually top down game mode so let's just change this to a top down game mode change the variable type that's going to mess up uh a little bit in our construct so we're going to have to go back to that and we're going to because it's not going to be able to do this if we try to plug this in you see how it doesn't work so we need to cast this we cast this to a top down and once again reminder casting all it's doing is saying is this game mode a top down and if it is continue and give me access to all its stuff so let's just do that compile that again and just out of curiosity if we go back to our designer do we have any more than we had before in our bindings oh yeah we do we don't even need to do this okay so let's remove our binding so by creating our our game mode properly properly by casting to the right right type when we click on bind now under game mode it's kind of offc screen I can show you actually if I just resize this a little bit just so you can see what I'm seeing if we click on the bind button here you'll notice that now our game mode game mode has a score option so we can just bind it straight to the score option by doing that when we when we run our game we don't even have to do any of the work to set up all those all getting the variables and doing all those things uh manually we can just go ahead and use that that's great now for our health bar this one is a little bit different we need to get our player for us to get the health we need to get our player and we need to get the health component so let's go ahead and do that so let's get our player get the player and we are going to take the player and we are going to cast this to I believe our players of top down characters which is great and if this is successful we're going to get the health component get the health component with that what I want to do is I want to um let's go ahead and promote this to a variable and the reason we're doing this is we'll call this player let's call this component player help the reason we're doing this is so that we don't have to recall it Etc let's compile this let's go back to our G score we don't actually need this anymore and let's go back to our designer is what I meant to say and then down here for our health bar for our progress we are going to create a binding for this one because remember we have to do a little bit of math so in here for the progress bar we are going to create a [Music] binding by clicking on create binding and then remember we want to do this in the proper order this time so let's get our player health component let's get the Mac current health get get get the health that's our current health let's get our Max health and then we're going to divide the current health by the max health so if our current health is 100 Max is 100 this is going to be one if our current health is 50 and our Max is 100 we're going to get 0.5 so that's going to create that binding okay so our widget is ready now all we need to do is we need to tell our HUD to spawn this widget so in begin play what we're going to do is we are going to create a widget I believe yep and the widget that we're going to create is our new HUD widget so let's just type HUD in here it's a TSS HUD and we should be able to just simply add this to the viewport now when we do this we're almost there if you've gone through our hord mode tutorial you know that what we need to do now is we need to actually uh change our default HUD for our game mode so uh if you're looking at your map you need to make sure you have your world settings window your world settings window is over here if I just pop this up here if we take a look at the options there's our game mode override and in our selected game mode you can see we have the HUD so there's two potential ways to do this what we could do is we could go and we could take a look at our game mode and we could change the HUD right here so if we just change this to HUD TSS compile and save that when we go back you'll notice that this now defaults to HUD TSS or if we potentially have different ones we could just overwrite it in the world settings here okay so now when we play do we have a HUD and does it work we do not have a HUD oh wait we do we have a score in the top right but interestingly enough we do not have a progress bar at the bottom so we got to figure out what's going on with our progress bar so let's do a couple things with this we know it's here but it looks like it's potentially off screen so let's take this overlay and let's get rid of let's check our alignment okay there we go so that's our this maybe our alignment was pushing us off screen and I'm also going to change the padding to be maybe 50th the bottom oh oh no we don't want that uh let's let's see here our [Music] overlay offset right and left first let's just see if we see it was that our actual problem yeah okay so we have a giant health bar now which is great oh our giant health bar is hurting okay so that actually that actually did it um we now we may want to right now we're doing this as percentages we could specify a specific size whatever it is we want to do but the overall bottom line is we have our health bar now I might put put some kind of padding below this as I mentioned we have our position we have our anchors let's see here we could do this pretty simply you know what let's wrap this we're going to go ahead and write click and we're going to wrap this with a vertical box a vertical box every element you put in it stacks on top of the next one was in our overlay we can set the size to let's say 60 for example that's going to make it twice as tall and then on our health what we can do is rather than filling vertically we can align at the top all right so now that we've aligned it to the top we should be able to pad the bottom let's pad the bottom with 40 30 that's good okay so that should give us our health bar a little bit off the bottom there there we go that feels a little better now obviously you can go ahead and set up your you can go ahead and set up your your health bar however you want that doesn't get in the way it's rightfully big and it's pretty apparent that I'm going to be hurting here in a second all right so we're in a really good place with our UI we got our health bar we got our scoreboard now what we need is we need a we need a win screen we need Victory defeat pause restart resume all the all the good buttons now we could probably give this a shot as just part of our current HUD so maybe what we do is we create another overlay for example or actually probably let's just do a vertical box so let's do vertical box let's drop that inside of our canvas and inside of this vertical box we're going to add in uh text the text is going to be in this case let's set this to Victory and we are going to make it a lot larger so let's do something like that for example and I want to take my vertical box and I want to inchor it right in the middle of the screen I think so to do that we're going to go to our anchors we'll go middle we'll reset all of our offsets and then we need to change okay so here's what we need to do we need to change our size so if we go size the content and then we go 0.5 and 05 that will get our Victory right in the middle of the screen UI stuff is fun okay so we have our Victory now I want to be able to change this text so there's a couple different ways I could have different text or I could change what's in the text I'm going to go with different texts in order to do that what I'm going to do is I'm going to wrap this with an overlay so let's do this I believe it's an overlay that I want and the reason being is if I duplicate this I want a defeat defeat and one more for let's just go sure we can add pause let's go ahead and add pause as well and let's make pause a nice blue color and let's make defeat a nice red color and let's make Victory green okay so what we want to do when we first start not our game mode in this HUD let's go ahead and uh we can get rid of this here so on our preconstructed up here in the top right let's check the box for its variable because we need to be able to set these there going to be a text defeat make sure it's a variable and text pause and is variable and we're not going to handle pause quite yet but let's just start with with these two and then in our graph back to our graph let's go ahead and take our text pause and set the visibility and we're going to set it to um hidden so we're going to do that for all of these text defeat hidden and fortunately we can connect more than one thing to this same pen so it just helps keep our our graph clean text Victory okay so when we compile that when we go back to designer we shouldn't even see them here they're hidden they're hidden because by default uh that's the way it is and what we can do is in our game mode what we can do here is spawner count goes to zero rather than printing the string you win what we can do is we can uh what we can do is we can tell the HUD that they have uh we can basically tell it to pop up the wind condition screen and to do that what we need to do is we need to get we need to get our HUD so this is our top down game mode can we get our HUD from here get the HUD get the HUD class that's the that's the class so let's get the controlled control get the player controller and with that let's get the HUD can we get the HUD from this yes we can so here's our HUD and what we're going to do is we're going to cast this to a TSS HUD and with that we are going to with a HUD PSS we are going [Music] to oh interesting we're probably going to have to store a variable for this widget because it's stored there every time we've done this in the past what we did is with the HUD was a separate CL or the wind screen was just a separate screen that we popped up because it's part of the HUD we need to do a little more work okay we can do that so rather than just adding it to the viewport let's promote this to a variable that way we have access to our HUD later and this is going to be our uh HUD this is going to be our TSS H okay and then what we want to be able to do is let's do uh let's add an event in here let's do um a custom event and the event that we're going to add is vent victory and for that we are going to get our HUD and we are going to off of here we're going to say show Victory so in our HUD we need an event to show Victory so let's come over here and get rid of this tick we're going to add a custom event here as well this going to be event show or handle Victory whatever you want to do show victory for example this is going to be very straightforward we're just going to set the visibility of the victory text and we're just going to set it to visible and then while we're here since we know we're going to have to do this to the others let's just go ahead and show show defeat because that is going to be easier to test because uh we get just destroyed by our enemies so fast so event defeat and let's set our visibility to visible and it's the defeat text there we we go Okay cool so we got that now what we also want to do is so now that we have those we need to go back to where were we we're in the HUD so on Victory we need to take I'm going to compile and save this by the way we need to take our TSS HUD and call Victory so that's our event show Victory which is cool and then let's go ahead and create an event um add another custom event and this custom event is going to be event feed and once again we're going to get our TSS HUD and then we're going to do a defeat so now our HUD container knows how to send the message to the actual widget that is the HUD and then all we need to do is in our game mode with this HUD we can just go ahead and what were we doing here we were oh this was our Victory so let's do victory and this should create a victory for us so let's see if we can test that real quick we got to kill all four oh my goodness let's try defeat first let's see when we our defeat is done on our players so let's go to our blueprints top down character and where do we ragd doll begin do effect Health effect health comes in spawns the system destroys the actor if it's a player we disable input we set Collision enable we set simulate physics so the other thing that we want to do here is let's do we have the controller already we do we have the player controller so let's get the player controller get the HUD and we could we'll just go ahead and cast this to a TSS HUD and from that let's just do show defeat let's see if that works that's going to be easy to test defeat here's a defeat okay so theoretically in addition to getting raged all now we're going to go ahead and try to win if we can but if we end up losing it'll be all right there's defeat okay so our HUD is working which is great so we just need a couple more things that we want to add to that uh let's see here how many characters are these spawning these are each spawn under our details one man I am getting wrecked with one enemy so let's go let's try setting these to zero for a second just to see if we can just double check that our Victory works and go so this is the only one that should spawn although we have never tested the zero condition on our spawners Victory okay so both Victory and defeat work perfect okay so now we have our Victory or defeat we need a couple buttons so let's go back to our UI we have this nice overlay let's go ahead and drop in a button onto our overlay this button not a border a button a button this button is going to be called button restart for example we're going to make it a variable yes please and for now let's just go ahead and fill that now interesting ah it's because I parented it to the overlay I don't want it in the overlay I want it in the vertical box and the reason I want it in the vertical box is I want to St I'm going to need I'm going to need a couple buttons but just to help us keep them straight let's drop some text on this restart button and we are going to label this when we pick our text as restart and I'm going to make my button a little bit darker because it'll be easier on the oh that's the text I want the style normal and under tint let's just go ahead and drop let's just drop this down so it's a little easier in the eyes there we go and then let's do some padding Let's do let's say on the left 50 or is that 80 that's 80 we go 50 uh yeah let's do 100 and 100 okay so we got a little bit of padding and now we have a restart button now I'm just going to duplicate this I'm going to call this button restart and then we have button quit and let's go ahead and change the label on quit so we have restart and quit and I do want a little bit of padding in here let's say 20 between the buttons that's good and let's duplicate this one more time and we're going to call this re Zoe that would be if we paused our game um wow this this tutorial is going to be beastly there's so much in here so this would really only be if we pause our game we we're going to have to do some switching of hot keys to do that reasonably so let's go ahead and do resume okay so we have our button for restart resume and pause let's put some padding at the top of I believe we did 20 okay uh we're going to double that I don't want to accidentally click one versus the other so and we'll even put some padding here so there's some padding between the top so we have resume restart resume and quit now here's the problem when we start this these are all going to show up on our screen when we press play we don't we don't want these to show unless uh some conditions are met the conditions are met would be we pause the game we have a defeat or we have a victory so let's go ahead and take each of these and hide them as part of our construct so we're going to take each of these three uh buttons and we'll hide it we can just feed it straight in this is great that's button quit let's get our button restart and finally our button pause quit uh resume okay so now there everything should be hidden which is great and then what we want to do is when we do Victory we want to show our buttons now so as part of that they we can basically take well actually we can just copy all these we want all three I think actually for a victory screen we don't need resume we need restart quit and there we go Zo now we would potentially change this slightly in the sense that like if for example Victory there's a difference between Victory and beating the current level we're on we would just have to change the functionality a little bit if we were to go to another room for example to beat the whole dungeon as an example all right for the defeat screen what we want is we want quit and restart we don't need resume so let's just take those connect those in and now let's just see if we can test these so first things first let's get rid of our spawners before anybody comes was a little slow all right so we're going to test Victory first Victory so we have restart and quit so now what we need to do is we need to connect these so in order to do that well let's just go ahead and double check our our defeat first where's our enemies Here Comes one defeat oh man he wrecked me so we have restart and quit which is perfect okay so when we what we want to do in our widget is we're going to go ahead and for our button quid let's add on clicked okay and after we after we add our on clicked this is actually pretty straightforward I believe we can just call Quick game which is great so we don't have to do anything specific we don't need a specific player or anything like that and what we can do is we can go ahead and press play and then we can either try to win or we can see which happens first we get that spawner here's our Victory it's ours and can we quit yep that pops us out okay so very quickly we have a quit restart is a little bit different what we're going to do with our restart is in our game mode we're going to create an event here so let's add a custom event and this is going to be event restart and what I want to do in here is I want to basically I believe it's open level by name and let's see can we get level get the current level name there we go so all we do in order to restart is we just basically reopen the level now there's two different ways to restart uh we actually covered both in the mob dash one is you basically open level by name the other one is you execute a console command which is basically I believe it's restart level so in here I think if we just connect this up what we can do is now we just need to call event restart when well uh yes we need to call event restart from our and this is res start so let's just change this restart we need to call that from our HUD when we click on restart so over here on the left on click what we need is we need our game mode we do not have that so this is currently our HUD our HUD does or does not have the game mode it does not so let's go back into our the HUD for our widget let's get on begin play Let's get the game mode oh wait we do have the game mode and we set it did I just miss it oh wow it's just okay it was just hidden down there okay so we do have our game mode we don't even need to do that so for restart we're going to get our game mode and then we're going to call restart because we made because this game mode is a top down game mode and that event is specific to that one we should just be able to call restart now what this should theoretically do is whether we do Victory or defeat we should be able to just go ahead and quick uh click compile I'm sorry click restart and restart um restart the match so let's go ahead and do that okay so if we restart there we go that's it so just like that we have a restart a quit and we do not have a pause yet pause is a little bit different so I don't mind that our character can run around during our Victory or feet screens pause we need to do uh basically what we want to do is in order to pause our game we're going to have to do a new keyboard binding so to do that we're going to need a new input action this is all part of U UI stuff it's kind of fun right all right so let's just go ahead and take and create a new input action this is going to be our input action pause and what we can do do is in here we can it's digital bull that's fine let's save that let's go back to our input and what we want to do is in our input mappings we need to go ahead and add in one for pause so here's pause now in order for pause to work what we need to do is we need to give it a key now a lot of times what I see happen is uh we swap the Escape key to basically be the pause because that's what people think of but for now just for ease of implementation we'll just go ahead and put it on the P key okay and with that now we can pause our game with the P key if we press escape the problem is escape by default in the editor is end the experience quit the game what we would probably need to do is change it to shift escape and then add Escape as a thing U although you know what we'll try something in a second for now let's just get this working with the p ke all right so that's our input and then what we need to do on our top down character here's our top down character oh remember all this stuff's on the controller so let's go back to our controller for our inputs here's our top down controller and what we're going to do in here is we're going to add in a uh pause here's our IIA pause nope that's not what I wanted I want our event pause enhance input action here we go when this is triggered all we need to do is we need to get from our variables we do not have the game mode so let's see here let's see if we can do all of this without the game mode so when this gets triggered what we're going to do is we're going to um disable input and no we need well this is the player controller self okay and then let's see if we can also we also want to pause the game can we pause the game here pause game set game pause we can we can do that without getting the other stuff so first thing we're going to do is we're going to pause the game then we're going to disable input so nothing's happening so that should take care of that I was actually thinking we need the game mode but we should just be able to get the HUD and tell the HUD to tell the game mode what to do so let's try that so let's get get the HUD and let's cast this HUD to a TSS HUD and with the TSS HUD what we want to do is we have event Victory event defeat we need to do a let's add an event a custom event for event and I'm going to be explicit with show pause the reason I'm doing that is because unlike Victory and defeat we need to be able to uh we we need we we're not actually changing the game State okay so here's what we're going to do in this case we need an event for showa PA yep so let's just add it so right here let's just add a custom event it's going to be event show pause and we are going to take and we're going to set the visibility on our restart actually we're going to set visibility on all of them in this case so we're going to set restart quit and pause see here pause and resume that's the one we're missing okay so down here here's pause so we have resume and pause so we can do all the things when we're doing the pause okay so let's compile that let's go back to our HUD and when we do this we are going to get our HUD and we are going to show the pause which is good okay and then if we go back one more I'm using control tab by the way to switch back and forth with our HUD we should just be able to show pause okay so whenever we press the uh P key we should be able to do a pause now so there's P we're paused now I can't move I can't do anything the cool thing about the top down shooter if you remember or if you did the mob Dash mini game we had to do a lot of work to still show the cursor and a lot of other things but because the top down shooter has the cursor visible already we don't have to do any of that so let's test resume it does nothing but quit Works still which is great so let's go ahead and actually let's just go ahead and test our restart from here okay so restart works as well so we actually just need to connect our pause now so let's go back to this widget and what it is is our button for pause which is resume I don't know why I did that so our button for resume because I I know why cuz I didn't want to call it unpa over here on the left we're going to add our on click event now this one we do need to do a little bit more work because back here in the controller we set the game mode to pause and we disabled the input we need to reenable the input and we need to set the game to pause and we need to hide all of the widgets that are as part of our HUD that we don't want to see when the game is actually being played so uh let's start by setting the visibility on all of these back to Hidden okay so these are all going to get hidden so now our UI should disappear let's set our pause set our game mode to not paus so basically unpause which is great and then we should probably let's reenable our input before we unset the pause just in case so to do that we do need to get our player controller do we have them anywhere we H we'll just get let's just try get player controller or can we disable input no we need the player controller so let's get the player controller and let's enable input and then the player controller that's the actor okay so that should be our Pawn so we're going to do this so let's also get our control Pawn get player Pawn okay so we'll put the player Pawn in here just in case so we're covering all of our bases and we should be be able to resume okay we are almost there with UI all right so if we press pause and we go to resume I uh we haven't we didn't get it right um and in fact but we did get it right from the standpoint that the enemy still spawn the game is going but our inputs are not actually getting re-enabled so let's see what we missed here if we go back to our top down controller we disabled input on our top down controller so we didn't feed the pawn into this one here so let's see if that's our problem so we'll just basically try testing that by going ahead and reconnecting that like so we go ahead and press P for pause we pause we can't move we'll resume and now we can move again that's all it was so we basically disabled input on the on the controller and we needed to to reenable that all right we got our UI our game is actually really shaping up I know this is a beast of a tutorial but I kind of think we need a weapon here's why right now our character is able to shoot projectiles but it's not really associated with the idea of a weapon and any twin stick shooter probably has more than one weapon so it would be really cool if we took this as an opportunity to show you how we might implement a couple different weapons now before we just hop in and start building stuff let me explain to you what we're going to do we are going to build a weapon blueprint that blueprint is going to be something that the character can use and activate to shoot so we're going to need a weapon blueprint we're also going to have to move all of the projectile we work that we did in the character into the weapon so that the individual weapons can control how they shoot or not so we're going to be doing some work there and then we also are going to be adding the idea of uh some kind of gate or limiter like attack speed so let's hop in and get started on that part of this so what I'm going to do is I'm going to create a new folder here I'm going to call this weapons weapons and inside our weapons folder we're going to need a new blueprint and this is just going to be an actor and this is going to be blueprint weapon base and since we crashed we're also going to fix this real quick so you can read this better okay so now that we have our weapon base what we want to do is in here let me dock this we basically in our event graph we need to set it up so that we can activate our weapon so so we don't for right now I'm not going to worry about begin play or overlap or anything I'll just go ahead and delete those and let's just say add a new event add custom event and this is going to be event trigger weapon for example you call it fire weapon attack whatever you want to call it and what we want to do in here is we want to do everything everything that we were doing in the character to shoot the projectile so we need our character so let's go to our character and we were doing that in the top down controller I believe where's our attack here's our primary attack okay now what we want to do is we basically want to do all of this but inside of our weapon instead so let's go ahead and grab that and I'll paste it in here and we're effectively going to spawn a projectile however we do have we do have a couple of things to potentially look at this will still work because we're getting the well the controlled Pawn here is actually slightly different and what I mean by that is in the character in the controller when we get the controlled Pawn it's getting us the actual pawn and so we can use that to get the facing so we know which way to shoot our projectiles but the weapon the weapon is going to get attached to the character and if it's attached to the hand or anything like that it may not know where it's attached to so what we are actually going to do is we're going to delete this first off and what we need to do in our weapon is we need to have some idea of the weapon owner so let's add in a reference let's create a variable for that for weapon owner and the reason I want to do that and what we're going to do is we're going to set this to type this type is going to be uh top down character and then what we are going to do rather than getting the controlled Pawn we're just going to get our weapon owner and with our weapon owner we're going to get our actor transform and we're going to set this as the instigator and we're also going to set it as the owner of this projectile that we're shooting Okay so we've theoretically set it up so that when we trigger our weapon it will get whoever the owner is of the weapon and it will use all the same stuff to figure out which way our facing this but we do need to now equip this weapon so let's go back to our controller and let's add a variable to our controller this is going to be our primary primary weapon and I'm calling it primary because with this knowledge you can later on go on to make secondary whatever else you want let's call this a weapon base and so that is our weapon based reference now we need to set this so here's what we're going to do right now there's we don't have we we've done nothing to actually equip the weapon so let's go ahead and create an event for equipping our weapon so I'm going to add an event it's going to be a custom event this is going to be event equip equip weapon and what I want to do when we equip the weapon is I want to get our primary weapon I want to see if it's valid already is valid and the reason I want to do this is what is going to happen later is if we pick up a weapon but we already have one what do we do with the one that we already have we're going to destroy it so if we have a primary weapon and it's valid what we are going to do is we are going to destroy this actor destroy that pretty straightforward then what we're going to do after let move these up here because a lot of the the bulk of what we're going to be doing this down here is if we don't have a primary weapon we need to spawn one so if it's not valid we are going to spawn actor from class spawn actor from class the actor that we're going to spawn in this case is an uh not an enemy a weapon and then what we want to do with this actor is we want to attach it attach actor to component now we could attach actor to actor actor to component whatever you want I'm specifically choosing the component because what I want to do is I want to get I actually want to get the skeletal mash and I want to put it in the right hand for example if you have a visual so the parent is going to be the controlled Pawn so in this case we have controllers get the control Pawn we may change the way we do this here in a second here we go get our control Pawn can we get the mesh from this okay we can't get the mesh from this so what we're going to do instead we what we can do instead is we can we could do a cast for example that's interesting or we could do our equipping on the pawn itself it's kind of actually it's kind of weird that we're doing this on the controller no because we may want to change our type okay so let's go ahead and do the cast what does that mean it means that what we need to do is we need to get the controlled Pawn so as we just did if we get the controlled Pawn get the controlled Pawn we have no concept of what this is right now okay so what we need to do is we need to check to make sure it is a top down character and the reason that we're doing that is because when we have a top down character we can get the mesh and with the mesh we can then attach it to the right hand left hand whatever you want to attach it to now here's the thing do I want to do this every time I equip a weapon or when this starts do I want to store the controlled Pawn for example as a variable I can reference later uh we could do either one let's see what we have in our begin play right now yeah let's do this in our begin play that way we have a variable okay so here's that so the logic of why we're doing this to begin play is because we won't we don't want to do this every time we equip and unequip even though it's not that expensive so here's what we'll do on begin play we're going to get the controlled pawn and I'm going to explain to a little bit of um thing to watch out for I'm going to promote this to variable get rid of our mesh for right now and so what's going to happen is it is going to set this and we're going to rather than calling this as BP I'm just going to call this controlled controlled Pawn okay so now this is available to us to use all the time I want to caution the example I used where if for some reason you swap out your Pawn you will need to update this okay but we're not going to worry about that for now but what we do now have is we have a variable we can use and so what we're going to do is we're going to take a controlled Pawn we're going to get the mesh and we are going to fill that into the parent and then I'm going to attach whatever it is to hand right for example and we can do snap to Target snap to or snap to Target for both location Etc what that would do is if we had a visual it would snap it in place so it's in the character's hand and maybe we'll just add one for demo purposes here in a second but for right now we just need to get our weapon based spawn and attached and attached to our character the other thing that we want to do when we spawn this weapon base is we want to set it as our primary weapon all right this is all in our equipping of the weapon so we've assumed at this point that if we had a primary weapon we destroyed it if we don't we're going to spawn one and we want to set our primary weapon so let's go ahead and do that as part of this section and now we have a primary weapon that has now been attached now the other thing that we need to do though is after we destroy the weapon that is already in place we do need to go ahead and continue to spawn the new one now eventually we're going to need to make this variable the type of weapon so that we can choose what kind of weapon we are going to equip but for now we're just trying to get everything set up so that we can actually uh trigger our our fire so let's see here oh we need a transform so let's make a transform and connect connect this in so we do need to have a default transform for this even though we're going to be doing the snapping here all right so let's compile that let's save that and now that we have our weapon we need to be able to trigger the weapon so what we're going to do is let's take our primary attack and then all we're going to do is in our primary weapon we are going to to trigger the weapon now one thing that might be worth checking is whether or not our primary weapon is valid here and the reason for that is if it's not we don't want to be trying to trigger an invalid weapon so theoretically we've gotten rid of all of our old way of doing this and now when we begin play our character should have a weapon and we should be able to shoot so let's see where we are at okay right now we missed something so let's take a look we have our primary attack we check to see if our primary weapon is valid it may not be valid because it's possible that our equipment is not getting equipped oh we're setting our control Pond but we don't we haven't actually equipped a weapon yet that's all it is so let's go ahead and equip also as part of begin play equip a weapon now this is just going to equip our default weapon for now and we can try that again okay so it is trying to fire our weapon here's our equipped weapon it does all of the work and it comes through here it attaches it to the right hand there we go now let's take a look at our weapon base I want to know if we're actually doing this so let's print ah I know what's going on let's print this string we should see this hello when we when we trigger you can see it printing hello on the top left however it's not actually spawning our projectiles why not the reason is right now we don't have a weapon owner our projectiles are being spawned somewhere off in the middle of nowhere so what we want to do is when we spawn this weapon we want to assign our weapon owner we want to tell it who the owner is so in order to do that we need to make it instant editable and expose on spawn so compile and save that and then we got to go back to our top down controller and when we equip this weapon when we spawn this weapon base if I right click here and refresh this you'll see there's now a weapon owner option here I want the weapon owner to be the controlled Pawn okay step by step so you all can follow all right so now that we've got that we can now actually shoot again now that means that we can get rid of our hell we don't need those anymore and we still have our Victory conditions which is great so we have successfully converted our weapon or not our we we've successfully converted our attack to a weapon based attack which means now we can create additional weapons so let's go ahead and make let's make a new weapon let's make a split shot and then I'm going to show you all how to pick up different weapons and swap them out so let's take a look at that so to create our second weapon what we're going to do is we're going to leverage our first weapon and the way we're going to do that is we're going to use something called inheritance now I'm going to introduce you all throughout this tutorial to a couple even of the more advanced topics like inheritance and blueprint interfaces and things like that I'm going to explain them hopefully in a way that you will understand you may not have wrapped your head around them but at least you will have had an introduction because the goal is to try to teach you how to do these things the right way so what we're going to do is we are going to go ahead and right click on this and we're going to create a child blueprint this is going to be B uh blueprint uncore splitshot let's call this splitshot and let's have a chat not split shot let's have a chat about how this parent child relationship works so splitshot is the exact same thing right now as weapon base it does all of the same stuff it shoots it has an owner it has all those things however we have the ability to override things so let me show you let me show you in practice what I'm talking about right now we're spawning weapon base if I change this to split shot what I want to show you is when we play our game we can still shoot okay if I go back to weapon basee I can get rid of the hello even though I'm changing weapon base I'm not changing split shot compile and save and when I press play you'll notice that I'm not printing hello it is doing exactly what weapon base does so what do I mean by when I say I can override it well what I can do is because our parent basically in is inherited down in the child the child can do everything the parent can it understand understands everything that the parent has it has all the same events Etc but the parent cannot do everything the child does so if we change the child the parent won't know about it so let me show you a good example of how that works so what I want to show you here is in our functions let's do uh trigger I'm going to call trigger so you'll notice that we have this event trigger weapon no I don't want to call it uh ad event trigger add event event trigger weapon okay so if I just add this event and I do a print here what's going to happen is when I press the trigger button it is going to print hello but I want you to also not what else happens I'm pressing the button it's printing hello on the top left but look there's no projectiles there are no projectiles because the child this child ad or event trigger your weapon is basically the overriding with the parent had going on in the event trigger weapon so what I want to do is I want to change this I want my child to do the same thing the parent does and to do that we do something called add call to parent function so now if I leave this if I just go ahead and if I play right now it won't print and it won't shoot if I simp connect in this ad call to parent what this means is here's the child trigger weapon I want to do whatever the parent doing and then I want to continue on so I'm going to print a string here for child so here's what's going to happen now even though we don't have a print in the main weapon we do have one in the child so as long as it's a child you'll see it's printing child in the top left that's because that what's happening is we're doing what the parents said to do plus we're doing whatever is in the child so here's what we're going to do in this child blueprint we're going to create a split shot so we have let's copy all of this information we're going to yeah we're just going to copy these and I'm going to take this and I'm going to paste this in split shot the reason I'm doing this is because I want the projectile from the parent and then I want two more one on each side so I need two more projectiles now the the rotations of this projectile are going to be a little bit different so let's um break this connection and split this and then what I want to do is I want to take the rotations here and get the forward Vector so what this does is this gets which way our character is facing and then I want to take that and I want to rotate it 10° to the right for example so what I'm going to do is I'm going to take this vector and I'm going to rotate it I'm going to rotate vector and it gives me an angle that I can type in so let's do 25° here's 25° and then what we'll do is we are going to split this pin struck here and we will go ahead and connect in all of the stuff so our position is going to be the same our our rotation is going to be this new rotation of a 25° we'll see if we got the axis right here in a second and we can leave our scale as one for now I'm going to skip the call to the parent and I want to just see the 25° offset okay it's not super pronounced but it's there we have a 25° offset in our projectile so that's working now if we add back in the parent which shoots a projectile Straight Ahead we should have our parent projectile plus our child projectile but we may not and I'll explain why in a second we don't why not let me show you what's happening so if we come back in here when we spawn our Pro projectile if we come into our projectile what I want to show you is when our projectile begins an overlap it checks to see if the other if if it's overlapping it's uh instigator and if not it goes on and does it continues to do the work now there the problem is both projectiles are spawning in the exact same position so they're already on top of each other so they're already hitting each other so they're destroying each other and we can see that because if we put a print string here we know that it's coming in here you can see it prints hello so we know it's getting there and that is exactly what's happening so there's a we have a couple of options here one we could change our Collision presets for our projectile to only overlap pawns so let's try that one so let's over overlap only Pawn let's compile that and save it and then go ahead and try so now we have our Double Split shot projectile it's pretty cool and the reason the reason that's working is because as I said we are we are no longer colliding with our own projectiles now the other thing that we could do instead of overlapping only Pawn is we could also test to see if we're hitting another projectile but this really gets into how you design your own experience do you want bullets and projectiles to be able to hit each other or not those kinds of things and you can set that up so that was a quick little explanation what's happening there but let's get back to our split shot so we already have one shot now let's do the same thing but this time let's rotate the vector again rotate the vector and this time rather than positive 25 let's go -25 and we are going to do the exact same thing we're going to spawn a second projectile in here so we're going to come into the first one and we could probably use a sequence I pressed s and left clicked right there that creates a sequence the way a sequence work is it basically goes in sequence it does the items in the first slot when it's done it comes back and does the items in the second slot okay so we are going to take these values and we are going to connect them into both projectiles that's our spawn transform this is our rotation we can leave our scales so at this point we have created a split shot and our split shot takes what our parent is doing shoots which is shooting a single projectile and then it adds two more on either side at a 25° angle so let's see what that looks like defeat oh we are accidentally okay what happened there we accidentally destroyed ourselves that's because we did not connect in the weapon owner remember our projectiles are set to ignore the weapon own owner we need to connect these in otherwise we basically just shot ourselves in the stomach so here we go let's try that again okay so now we have our triple shot now this is a very wide triple shot for me I don't I don't actually like this angle from a twin stick shooter standpoint so what I'm going to do is I'm going to change that to be a little bit less let's go let's try let's try 5 degrees let's see if that feels better uh that's pretty good it's pretty powerful actually it's ridiculously powerful uh Victory we're so good at our own game okay so that's going along pretty well let's try let's try a little bit more maybe seven degrees on each side and then we'll call this done seven compile and save okay I think that feels pretty good which is great okay so now now that we have two weapons what we need is we need the ability to pick up the weapons so what we're going to do is we're going to create a pickup and the ability to equip each of those weapons to our hero characters so let's go ahead and do that using we're going to be using a combination of blueprints and blueprint interfaces kind of like we did with the health pack so let's hop in and take a look at that okay so in order to be able to pick up weapons we need a weapon pickup so let's go to our Blueprints and let's go ahead and create a new blueprint print class this is going to be an actor this is going to be our blueprint and I'm going to call this a nice generic item pickup reason we're doing that is because we're future thinking right now we have weapons but maybe you want to be able to pick up powerups or whatever else in the future you can always uh change this later so in our weapon pickup what we need to do is we need to be able to walk over a thing and get whatever the new item is that it wants to give us so in this particular case let's add a visual piece let's make that a cube or yeah yeah Cube this is going to be the pad that we can step on and go ahead and Shrink that down and I'm going to add this to my map just so I can check the sizing real quick that's reasonable 1 M by 1 meter okay so now that we have our pad we also need in our scene route let's go ahead and add a collision this is going to be our box Collision okay and we just need to size our box Collision to match our pad and basically all we're going to do is when the character walks on top of this and it collides with this box it is going to trigger the pad to give us the weapon so here we go let's do a couple things first off let's change this Cube I'm going to disable all of the Collision I want my character to be able to walk right through the thing I think ultimately my damage or my item pickup pads would be like some kind of cool mystical effect or something like that for example so no collision at all you can't walk up on it all that's great the Box though we do want collision and what we could do is we could just do um overlap only Pawn which is cool and no we can't step on it step on it and we're good to go okay so let's compile and save that and then what we need to do is we need to start wrapping our heads around how this is going to work so let's take our box right click on it and choose add event on component begin overlap now the idea here is when our character walks into this box it is going to trigger this overlap event and what we want to check to see is is the other actor the thing that is hitting this box is it a top down character so let's let's cast this to uh actually we don't even need to do that this is where the interfaces come in this is another actor what we want to do is we want to tell the other actor to equip the item okay but you'll notice that we can't equip the item so what we're going to do is we are going to create a messaging system just like we did for heal where this is going to be all about hey do you know how to equip items yes I know how to equip items well I'm sending you a message to equip the item and that that other actor will be like sweet thanks I will do what I need to do with that that's exactly what we're going to do so let's see what we have for uh blueprint interfaces so far currently we only have a health interface so let's create a new blueprint interface underneath our blueprint menu this is going to be blueprint interface and I'm going to call this combat for now because we may be doing other things I just need a generic one and in here for our first function I'm going to call this equip I'm going to be specific on this one I could say item but I'm going to go with weapon for right now okay and what all we're going to do is get the messaging service set up and working so we now have a blueprint interface that understands how to send and receive messages to equip weapons now we need to tell the item drop and the character how to listen and receive those messages so let's start with our item pickup our item pickup if we go to our class settings under implemented interfaces let's implement the combat interface which is like I said it's just subscribing to the understanding of that messaging system so now this character understands how to send a message to the combat messaging system called the equip so I can take this other actor now and type equip and you'll notice that it has an equip weapon option and it even has a nice little envelope for sending that message which is cool so we're going to have to make a couple changes to it but once again we're just getting the service set up first all right if we go back to our top down controller our top down controller is has the ability to equip a weapon however I want to show you something if we go into our item pick up I want to print or I want to get the display name on this we want to check to see when we do this overlap are we getting the controller or are we getting the pawn and this is important because this determines where we will put this information so in this particular case let's go ahead and print string and we're going to print the name of whatever this overlapping actor is so when we walk over here it prints top down character it is not printing the controller so if you recall our controller is the one that knows how to equip weapons but the thing that we're overlapping is the pawn so what we need to do is we need to bring up our pawn and now there there's a couple different ways to do this I'm going to try to keep it pretty straightforward so that you all can follow along because we're going to over because we're going to be sending the pawn the message we need to set it so the pawn can listen so in the implemented interfaces along with health we want to add combat so now the pawn can receive combat messages and if we compile underneath our interfaces over here if I right click on equip weapon I can implement this event and now if I print string here I can say Pawn equip for example not worried about the spelling right now it's just temporary let's go back to our top down no no let's go back to our item pickup and let's get rid of this print string we don't need it we know that that works we get rid of that compile and save and let's go ahead and play and when we walk over this we should see Pawn equip okay great so we've we've got Pawn equi but we haven't actually done anything with it so back in our top down character there's a couple options here we know for example that we could get get the controller here and we could cast as an example so if in here we get the controller get the controller and then we cast this to a top down controller with that we know that we can with the top down controller we can equip a weapon okay so this Loop will work however the trick or thing to think about right now is when we equip the weapon we're going to be equipping the exact same weapon every single time because in our top down controller equip weapon is always equipping split shot so we need the ability to tell it what kind of weapon to equip so here's what we're going to do I am going to take this class and I am going to drag it onto my event and what this is going to do is it's going to create a variable for me and it's called class I'm going to rename this I'm going to call this weapon class okay so now we can specify which one to equip however we do have an error here ah let's uh refresh this node and let's plug this into the instigator compile that we'll go from there okay cool so now that we have that let's go back to our character and our character is looking to pass this weapon class in but we haven't specified it yet so what we want to do is we need to be able to specify in our combat messaging system we need part of the message to be the type of weapon to clip the the the class of the weapon to equip so what we're going to do is I'm going to add an input over here and this is going to be weapon we weapon to equip or we could actually call it weapon class let's just do that that's a lot a weapon class and we want to set this to a weapon and I'm going to move this over so you actually let's just move this over here I'm going to set this to a weapon weapon type based class reference right let me move this back compile and save that so now when we go to our item pickup you'll notice that our item pickup now has a weapon class to pass in so let's promote this to a variable and what I want to do with this variable is I want to make it instance editable and exposed on spawn and what that is going to do is that means that when I pick the actor in My Level you'll notice over here on the right or I'm gon I'm G to drag this out so you can see it you'll notice over here I now have a weapon class option so I'm going to set this to I'm going to set this one to split shot all right and then I'm going to specify for this one let's set this one to weapon base so we now have two item pickups one for split shot and one for weapon base when we start our game actually let's finish connecting these first okay in our in our item so now that we have those expon exposed these get passed in we go to our messaging system messaging system sends that message to whoever's listening our top down character receives the message and here's the weapon class we want to pass that in all right let's compile this we'll save all now what we want to do for the ultimate test is let's go back to our controller and not equ a weapon to start so we're just going to unclick this so we're no longer equipping a weapon and when we start I cannot shoot but if I walk over this guy uh or this one neither one works actually so we missed something access none trying to read primary weapon attached to that might be a clue okay so let's see what's happening here when we come into our equip weapon what I want to know is I want to print this string print print string are we getting the name of the class when we do the equip so let's just walk over that and let's see what we get we do we get split shot and we get weapon base so that part of it is working which is good so we know that's good and then we come into our actual equipping of the weapon and in here when we ah we did not this is no longer connected ah interesting okay so what's happening is because we're spawning a class it does not know that the class of the actor that it's spawning is a weapon so what we're going to need to do is we're going to need to cast this to a weapon and with that let's go ahead and connect this in as long as that's successful which it should be we should be able to set our primary weapon now okay so let's try that test again we can't fire we come over this one we're shoot we can fire but notice that we're shooting from the origin that's no bueno okay and if we come over here we are also shooting probably from the or so let's see what's happening here access none trying to read property spawn actor PR BP projectile the weapon owner that is being set on the weapon base so are we not setting that spawn actor oh we're not setting it okay so we have one more thing we need to do here in addition to setting our primary weapon because the actor responding it doesn't know that it's a weapon base what we need to do is we also need to set the weapon owner so we're going to set the weapon owner and the weapon owner in this case is going to be the controlled Pawn we just have to make sure we fill in all these values so here's our weapon owner we'll drop this down just to clean this up all right let's try one more that way our projectiles are actually shooting from where they're supposed to be there we go we got our split shot now we got our single shot and if we walk back over our split shot we got our split shot back again okay A little bit of light debugging but effectively all we're doing is we have an item pickup the item pickup sends a message says hey some actor tried to pick this up do you understand how to equip a weapon the actor receives a message and if it knows how to receive that message says yes I do and then it actually equips the weapon for us so we have successfully set up our game to be able to handle the idea of an item pickup uh multiple weapons everything now we do need to implement the idea of attack speed here's why what I want to do is when we're actually shooting right now I'm having to tap every time this seems okay but watch what happens when we make our game harder if we make our game harder and we go back up to five enemies on each of these what's going to happen is I am going to get destroyed really quickly so what I'd like to be able to do is I'd like to be able to yep didn't make it what I want to be able to do is it's a twin stick shooter man I want to be able just to hold down the trigger so we're going to set it up so that we can hold down the trigger that's going to actually create an attack speed problem for us we're going to be way too fast so we're going to have to gate that with theack speed so let's take a look at how we could potentially add or the change that we can make so that we can hold down the trigger and then add attack speed to our weapons so in order to hold down the trigger what we need to do is we need to go back to our inputs and under our keyboard input for the GamePad trigger access let's go actually to the input action let's see if we can make that change in the action input action primary attack here's what we're going to do we have a digital Boolean the trigger right now is pressed I'm going to change this to down that simple change should make it so that when I walk over this I can now just hold this down oh my goodness like this game we we got this total Victory okay so that's pretty strong and that's why I was saying we may want the idea even let's see if we can even do it with single shot come over here we get single shot can we win our game with single shot I already won the game now interestingly enough even though I won the game I'm still being attacked so we're going to have to we're going to have to take a look at that for a second but overall even with single shot with infinite speed bullets I can totally I can totally own it so let's add the idea of attack speed okay so here's what we're going to do on the primary attack which is in our top down controller let's see where is that this is where we trigger the weapon now there's two places that we could potentially store this attack speed we could store it in the weapon or on the character I think I want to store it on the weapon because different weapons might have different attack speeds so inside this trigger weapon here's what we want to do I want the idea of a variable called attack speed and this is this is going to be a float I'm going to set this to float and then I need another variable for this to work I need last attack time which is also float so here's what we want to do with our attack speed if we compile this let's take our attack speed and let's assum assume this is attack speed in seconds I'm going to be very explicit with this okay last attack time in seconds all right now now when we want to attack if we set our attack speed to be one every 1 second I can fire a projectile what I want to do is when we trigger a weapon I want to get the last attack time and I want let's say let's say at 10 seconds into the match I click to trigger the weapon at that point that's 10 seconds and what I want to know is I want to know if the last attack time plus our attack [Music] speed is less than the current game time so what that means is if the current game time is 10 seconds 10.5 seconds is 10.5 seconds less than um 10 + 1 yes if so I can't shoot now let's go ahead and implement this sometimes I conf confuse myself when I save this stuff so let's let's get to where we're going to get time in seconds so we want the game time in seconds this is what we're comparing so is our game time in seconds greater than the last time we attacked plus our attack speed in seconds and if it is then we can actually trigger the shot okay if it's not let's just leave that empty for right now now if it is and we trigger the shot we also want to set the last attack time and we're going to set the last attack time to the current game time in seconds all right so let's run through this logic really quickly so you all can wrap your head around it okay press the trigger button at Time Zero the last attack time in seconds is starts off at zero for example 0 + 1 is 1 is the current game time zero greater than 1 no it's not so it wouldn't trigger okay but assuming that you probably take more than a second let's fast forward in time let's say we're at 10 seconds okay remember when we start the last attack time is zero so is last attack time is 0 + 1 is 1 is 10 seconds greater than 1 yes it is if that's true we're going to set our last attack time to 10 seconds and we're going to spawn our projectile then we're going to come back through here let's say at 10.5 seconds well our game time is 10.5 seconds our last attack time is 10 seconds and our attack speed is one is 10.5 greater than 11 no it's not so it's going to do nothing all right so this is a way for us to gate our bullets or our projectiles from being fired so let's see what that looks like in practice and I'll also show you how we can fix this so as fast as I'm typing actually hold on a second ah we're triggering the weapon okay this is important look at what's happened here when I go to step on this the spawner you'll notice that the middle bullet the middle bullet is firing every second the two outside bullets are firing infinitely all right that's because this is a split shot and remember a split shot does everything the parent does and then continues on so we need to change the way our child inherit the ability to attack a little bit so let's do this let's go back and if this is true here's what we'll do Let's do let's add a variable and we're going to call this U Boolean B can and attack we'll set this to a booon and then what we'll do in here is we're going to set the value of B can attack to be the result of this and then we are going to use B can attack as our gate now by doing this we've actually created a uh we've actually created a bullan that now exists in both the parent and the child so if we go back down to our child which is the split shot after we do our call to the parent function what we want to do is that same test we need to check to see can we attack in here cuz we're extending it so let's go ahead and do let's get can attack and if it's true we will go ahead and attack and if it's false we're just going to do nothing all right so now when we play if we come over here and I hold down the button it's every second there's no way I can win this game by triggering this every second so we need to set some reasonable default attack speeds so let's take our default attack speed and maybe set it to2 for example on our weapon base and let's see what that feels like that's reasonable let's just say that this was a a normal level we'd want to start it out oh I got caught up on that on that thing I still got defeated but that is a much more reasonable starting point from attack speed and what we can do is we can basically customize this and you can even create pickups that would affect and change the attack speeds of your weapons for example which is cool Okay so we've successfully implemented our attack speeds but I wanted to show you a couple things we have uh an an issue where when we defeat look at our Victory screen shows up so we have the victory bug we have a couple little cleanup things like ear flicks that we want to get so this next section is literally all about just testing and making some fixes that make sense for what we want our start to finish twin stick shooter uh miname to feel like so let's hop in do a little bit of testing QA quality insurance see what it is that we want to fix so we can put a bow on this little mini game here we go okay so we know the victory thing is weird but it's going to be hard for us to find let me go ahead and save all it's going to be hard for us to find with our current camera so I want to actually change our current camera to be a little further out I find I'm struggling to see the whole map anyways so let's take a look at our spring arm and our camera and let's change this to let's say let's try 2,000 000 let's see if that is how that feels like I said this is a little bit of Polish all right that's better I can kind of see what's going on all right so now that we can see what's going on when we get defeated oh look at that this is what's did you see that the enemies are destroying the spawners so what's happening is they're spawning eventually they accidentally trigger destroying the spawner and if you recall our spawners when they are destroyed that triggers the victory screen so let's clean that up so to do that let's go to our enemies under blueprints we have our enemy base and remember the way that that was being done was with this Collision box when this thing overlaps something it triggers uh the damage and because our spawners know how to listen to the health system they receive the damage as well but what we can do think is we can just change it rather than overlapping all Dynamic let's first off we don't want to will step up on this let's change this to overlap Pawn only overlap only Pawn okay and see if that fixes our faulty Victory screen and we'll know because we'll see like see for example how is that did I accidentally shoot that one nope it's still being destroyed so I guess that is it is thinking that that is a pawn so let's go ahead and do this a different way so in our our spawners let's take a look at what our spawners are our spawner is it derives from character okay let's check to see when our enemy does the overlap what is it doing event do on begin overlap it checks if the other actor is valid interesting but for some reason it shouldn't be triggering unless it's a pawn but it is let's see here if we change this Collision to custom World Dynamic ah block I'm going to change this to ignore I don't know why the pawn is block so let's see what happens there does that do it we should not see the health on the spawners depreciating it's not okay that fixed that great so we basically just had to get our Collision presets so that our enemies weren't inadvertently overlapping the spawners and they weren't taking damage and you'll have to juggle this depending on whether your projectiles are supposed to hit the spawners or not all those kinds of things okay so there's a couple things else speaking of cleanup once we hit the defeat screen we don't want our game to keep continually to spawn enemies at this point game's over stop spawning so how are we going to manage that well what I would like to do is in our spawner we have our timers these timers increment spawner accounts they they do everything they do we have spawner this staggers our timer for spawning what we need is a we need a W for the game mode to tell us that the game state is defeat for for example so right now our game mode does not have any sense of that so let's go to our game mode and I'll show you what I'm talking about game mode we have no sense of in here what the current state of the game is so let's add one and I'm going to add let's go ahead and add two states Victory defeat and maybe uh let's just take a look at this all right so here's what we need we are going to create something called an enumerator an enumerator is a way for us to use an actual string it's a by string to represent a a b so that we can visually see and here's what I mean it's usually just better to demonstrate these things so if we go and we create a new enumeration I'm going to call this ene game status and in our game status what we can do in here is we can add an enumerator and this first enumerator is going to be called playing for example let's just make a couple different states playing let's add another one for victory victory let's add another one for defeat defeat okay now now that we've set these three variables we can now use these three variables so let's go to our game mode and I'm going to add a new variable this variable is going to be called game status and it is going to be of type of our new enumerator game status okay so when we start the game all right income and spawn count event restart let's do what do we have available for us under events add event event let's go with begin play for now all I'm going to do on begin play is I'm going to set the game status to plane okay the other option I could do is not even do this on begin play I can just set the default value for it to plane now we have a couple of things that we need to do as well if we restart our game we want to reset the game status so we're going to set the game status to plane if we restart as well okay now what we need to do is when we um win the game we want to set the game status to Victory so here we go this is where we win our game this is where we're decreasing the number of spawners we have this is where we show our Victory screen let's set the game status to you guessed it Victory and then finally the defeat happens I believe on the top down controller let's check on our event graph event oh no no it's on our Pawn top down character because that's where we're affecting health so in our effect Health do effect Health we affect the health that's inside of our component and inside effect Health we come in we do all these things if it is a hero character this is where we need to be okay it when we disable the input we set our Collision we simulate the physics this is all the rag doll stuff then we go ahead and we flash up the defeat screen right here what we want to do is let's get the game mode and I don't believe we have a handle to the game mode in here at all so we don't all right so what we'll do is we'll get the game mode we'll cast this to a top down game mode and what I want to do is if that is successful I am going to go ahead and I'm going to set game status uh status if I spell it right and this one is going to be defeat All right so now that we've set all of our game statuses this is being tracked now what we can do in our spawner which is here what we want to do is we want to set it so that if the game status changes it is not it does not continually respawn it triggers a basically a pause and invalidates all these handles Etc so let's think about this when this begin play starts it kicks off a timer we're going to need a handle to that timer we're going to need that as a variable we know this so let's go ahead and the way we know this is because we know we want to shut it down so let's uh right click on this and promote this to a variable and this variable we are going to name this is going to be our spawn timer handle spawn time handle okay so we start it triggers this timer and this timer is looping based on our spawn delay all we want to do is before we trigger our spawn our stagger timer handle is we want to see or at the same time we want to see if the game state is defeat or Victory or we could also check not pling so if it is what we want to do is we want to clear clear and invalidate those timers so here's what we're going to do we are going to get our game mode which we already have a handle to which is great we are going to get the status now what we want to do is we want to see if this is equal now when we do the equal you have to make sure you pick the right one you want to pick the enum equal and if you do that it will automatically fill in so you can pick from your nice pretty list so if the pl if the game state is Victory or we also want to check for equals defeat and not when I pick the wrong equal it happens to be all the time equals and then this one defeat all right now what we want to do is we want to do a branch and if either of these two are true Victory or defeat and I just said it out loud that's how you know what to do if Victory or defeat are true then we want to clear all of the timers and stop the spawning so let's go ahead and do that we're going to get this stagger handle timer we're going to clear it okay and then we're also going to get our spawn timer handle and we are going to clear it that way our spawners are no longer spawning so let's compile and save everything see how we did so first off off when we get defeated what I want to see is I want to see that our spawners are no longer spawning anymore enemies now you could also do something like destroy all enemies there's lots of different things you can do I think it's kind of cool seeing uh the enemies still stomping around um on you know doing their victory dances Etc so we got defeat we checked that that works great let's see about our Victory condition so here's what I'm going to do I'm going to close down a few things and I'm going to go back to ludicrous speed on the split shot so under Weapons Under split shot I'm going to change my this is split shot right Swit shot yes compile I'm going to change my attack speed to be 0.01 and I'm even going to move these pickups a Little Closer all right let's go Victory okay now I want to hang out here for a second make sure nothing spawns make sure we have no defeat screens popping up and then we need to test if we restart do our spawners restart yes they do oh they definitely do very cool okay so I think I think the only other screen that we should probably double check is pause so let's restart and pause okay our spawners aren't doing anything we can't do anything let's resume we're shooting pause everybody pauses our projectiles pauses so I don't want to jinx it but I I think we're almost done so before we put a bow on our twin stick shooter I do want to mention one last thing as to why we moved our weapons to be their own actors and the reason for that is Imagine right now when we started we only had one weapon imagine fast forwarding and you have 20 weapons but you're only using one at a time well the thing is you have to still load if all of those are part of your hero character you have to still load all 20 of those weapons plus all of the abilities and everything that go with it even though only one of them is being used that is not a very sustainable way to build so the whole reason we went through this exercise of being able to add weapons as a separate item that we can pick up and equip and do something with is because we're we're trying to Future think and that's what this entire miname was about it was about giving you a start to finish twin stick shooter miname to start to introduce you to the ideas of all the various aspects that go into it and at the end you actually end up with a very cool little mini game that you can tweak and add on and learn from and we may even be using this in future tutorials as a baseline because everybody will be able to just hop in and build their own version of it and we can talk about performance testing and how do we handle abilities or secondary weapons or any of the other number of things so that's it you all one twin stick nostalgic miname shooter tutorial as always your feedback is huge throw all your comments down in the comment section down below if you went through this tutorial you got your own little mini game running go ahead and uh hop in the Discord server share your share your win share your Victory uh we would love to see those kinds of things and again if you dig what we're doing here there's lots of different ways to support the channel I talked about those about 5 hours ago or however long it was ago we have the tips down below we have the patreon we have the super chats and thanks helping spread the word is huge it's all go moves towards making this channel sustainable and creating more future content for you all my name is Kevin I'll see you on the next one take it easy
Info
Channel: Ask A Dev
Views: 3,429
Rating: undefined out of 5
Keywords:
Id: Wg7BGVOOk5c
Channel Id: undefined
Length: 323min 22sec (19402 seconds)
Published: Fri May 03 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.