Block & Shield System (Part 2)! | How To Make YOUR OWN SSB Game | Unreal & C++ Tutorial, Part 47

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign what's up guys Sean the Bro here and today we're going to be going over blocking part 2 within our Super Smash Brothers and platform fighter tutorial series now in the previous episode of The Blocking mechanic we had gone over actually putting the character into the block State when pressing a button taking them out of the block State when releasing the button and setting up animations related to that so I can press the block button and I go into the block State the character labeled shown the Bro in the bottom left there if I press my block button I go into the block State now all these other characters can also do it you can see I can press all them at the same time they're on the Block animation and they remain there until the button is released in this episode we're going to have a block shield now we don't have visuals for it yet but we're gonna set up all the behavior for what a block Shield would do specifically we're going to set up block Shield durability and what that means is our Shield or our blocking State can be hit a certain number of times until that Shield breaks and then we enter the stun State and in the stun State we can't do anything after a certain amount of time passes within the stun State we will then return to idle so I'm going to go down to my characters in The outliner here and I'm going to pick one of them I'm going to pick my first character here because that is the character that is easiest for me to block with and that is the character that is labeled Sean the bro so in the bottom left here that is who we are picking now the yellow character named default next to them is the attacker so I'm going to use an attack and Sean the bro is going to block it let's run the real estate in the blocking state if I hit him again still stays in the blocking state if I hit him a third time the block will be broken and Sean the bro will be stunned he can't move even when I'm pressing his keys after five seconds or what I've labeled as 300 frames the character will be able to move and function properly again and we can actually demonstrate this even without having an actual block Shield visual I can go to my character and I can look for Block I have some new variables here that we'll get into adding when the episode actually starts but I have block Shield durability Max block showed durability and block Shield breaks thumb frames and so the max blockchild durability is how many hits I can have total the current block Shields are abilities how many hits I have left so if I'm blocking and I get attacked you're going to see the block Shield durability in the bottom right hand corner of this video goes down to two then it goes down to one then if I get hit again it goes down to zero and the character receives 300 frames of stun so now if I check something else character state you can see the character state is stunned and after those 300 frames they will automatically return to idle and then they can act this is just one of the ways that you can exit out of this Thun State you can also exit out of the stun state by mashing faster in some cases or just by taking damage that might knock you out of it but for now we're just going to be going through that flow of having their ability on our Shield or on our block it breaking and us going to the stun state with all that said we can go ahead and get started but before we do I'd love to give a huge shout out to my patreon members and YouTube membership subscribers thank you guys for everything you do I'm so incredibly grateful for all the support you've given it is so incredibly fun to work on and I'm glad you guys are enjoying it as well if you want to get caught up in the series this is episode 47 of the Super Smash Brothers and platform fighter tutorial Series so you can click this I card in the top right corner and it will link you to all the episodes the entire playlist that we've done to this point so that you can get caught up on the series alternatively if you don't care about that I do recommend watching the previous episode which is where we initially set up the blocking State as well as the animation that goes with it and that is this I card in the top right corner right here we are going to go to the code today because this is a code and blueprint project and we are going to go to our SSB templatecharacter.h this is our base character and in our e character State enum that we had I'm adding a new enum value now and that is the E underscore stunned I put it under the blocking but the order doesn't matter just add a new enum value so that we can set the character state to this value and when the character is done they won't be able to do much of anything now if we scroll down to our variables I want to have some new variables for our shield and for our stun so some of the ones that I was showing you in the live demo or the max block Shield durability block shell durability and blockshow breaks done frames additionally I also have stun frames which is the current number of stun frames so we're going to add all of these variables today I've made them all you property so that we can access them in the blueprint if we want to you don't have to do that if you don't want to I've given them a category of block and stun respectively Max block Shield durability is the maximum number of hits that a block can take before the shield breaks now this is the maximum so it's just the highest value and I'm going to put this as a default of three but you can play around with it as much as you want to get the value right in your game then we have block Shield durability and this is the current durability of The Shield so even if the shield can take three hits total if we've already taken two we only have one hit left so block Shield durability is the current number of hits that the block Shield can take before it breaks now block Shield break stun frames is the number of stun frames given to a character when their block Shield is broken this could be different for every character or you could have a global across the board so that all the characters receive the same number of stun frames once their block Shield is broken and I have stun frames which this is the current number of stun frames because even if the stun frames we have is 300 to start with it's going to decrement over time until it reaches zero or until it's canceled for any reason and so we still need to capture the actual number of thumb frames remaining now additionally within this logic I'm going to scroll down and I want to override a new function and we're going to override our tick function you may have seen this before but the tick function is a function that is called every single frame and this is essentially your update function now the tick function specifically comes from the a character class which is the parent class of our class so when we use the template we get this character created that inherits a character due to it inheriting a character we can override the functions that we have in that class if we want to do specific logic in our tick function so it might differ from what the parent class does in their tick function in this case we're going to need to use it to do this we can write our function like this virtual which just means that we're going to be overriding it then we have our actual function definition so void tick float at the time it has to be written like this because when you overwrite a function it has to match the function name and the parameters so void tick float Delta time override so virtual and override like I said they're just related to the actual overriding the function and getting it in this class this is the actual function that we're going to be filling out and that's our void tick Delta time now that we have those four variables and that function we can go into the CPP of our character and we're going to want to scroll down to where we set our variables and their defaults I have my three blocking variables here and I have my stunned variable here so I set my Max block show durability to three again you could change this per character or you can make it a global I'm just going to default to three for each character for now then I set my actual current block show their ability to Max block Shield durability the block shell durability will match it so if we change Max block shell durability to five the character will start with the durability of 5 on their Shield then we have the number of stun frames once The Shield is broken now I set it to an arbitrary 300 assuming your game runs at 60 frames per second that means 300 frames is going to be 5 Seconds worth of time this could be too short this could be too much but remember this is not seconds it's frames now this is going to be more important later seconds are fine to use timers are fine to use but specifically with damage and stun frames are really useful over times and you'll see that as we get into more stuff why we want to use frames over seconds then I also default the current number of stun frames to be zero because the character does not start stunned when they're in their entrance animation or when they're spawning whatever the case may be so we don't have to worry about that now we want to go to our take damage function and change a bit of the logic so let's scroll down here's my take damage function we only want to do all this take damage logic where we're adding to our damage counter and launching the opponent if the character was not blocking if they're blocking it's entirely different so above the first line and take damage I've added a new if statement out if character state is not equal to e character State blocking so if they're not blocking they're going to do all the same logic that we've already set up and take damage I've changed none of it however if they are blocking we need to go into the else so you can follow my bracket down that is all the if this else means that they are blocking if they're blocking when they took damage meaning they were hit by a strike hitbox we don't want to actually add to the damage counter we just want to decrease from a block show of their ability they're going to negate all damage Additionally you could have some chip damage that does damage them but they receive less damage we'll get into that sort of thing later in the series but for now we're going to negate all damage so we want to decrement block Shield durability meaning we just want to subtract one from it we want to remove one from it so if it was three and they were hit by an attack it now goes to two if it's two and they were hit by an attack it now goes the one and lastly if it's one and it gets hit by an attack it goes to zero in the case of it being less than or equal to zero that means we have reached our minimum value our block Shield is broken we no longer have a block shield in which case we need to do different logic so we actually need to make a new function that I've called Break block Shield so let's go back into that header file for a second scroll down to our functions and here is my break block Shield function so I did make it blueprint callable again but this is also not necessary you can leave it as just a code function for now if you want but the important part is that you have void break block showed here and this is the logic that's going to occur when our Shield is broken so back in the CPP now again if our durability has gone to zero or less than that due to multiple hitboxes flying at the same time whatever the case may be we want to say our block Shield has been broken in this case we want to go ahead and call that function now this is all that we have to do and take damage but just be aware the return damage counter still has to be outside of the if and else okay everything that was already in the function of take damage is inside the if statement now that checks to see if the character state is not blocking except for the very last line which is return damage counter thank you this is because the take damage function returns an integer so it must do that if you section it off and only put it in an if statement then it won't let you compile you're not able to not return a value to a function that requires a value so I recommend just leaving return damage out of it instead of trying to return it through the if and the else it's just extra work so just leave this line as the very last line the function outside the if and outside the else this point we can go to the break block Shield function so just scroll down to wherever you want to add it I added my two functions for this episode at the very bottom so here is my break block Shield so go ahead and add this and specifically I'm adding void a SSB template character colon colon brake block Shield right now it's very simple because we don't have any visuals for the shield so all I do is I set my character state to be the stunned State then I take the stun frames and set it equal to the block Shield breaks done frames because this is where we are getting our number of sun frames from we know that our Shield was broken and that's why the character is stunned once our Shield is broken our character will now be stunned for the number of frames you set up in the Constructor the last thing we need to do in here is set up the tick function so this is the function that we were overriding so notice we don't have virtual or override here you don't need them in the CPP putting them in the header file is fine so now we just set this up like a standard function void a SSP template character colon colon tick then our parameters which are float Delta time immediately I call the super tick function and pass in Delta time which means that we're going to call the parents tick function we still want to do all the logic that is in the parents tick function the a character tick function we're not overriding this function for the sake of removing logic that is within the parents tick function instead we're trying to add to it so super colon colon tick passing in the Delta time parameter will call the parents take function then we can go and additionally add the rest of the logic that we want to do on top of that now we're just going to check to see if our stun frames are greater than zero even if we're not in the stunned characters they our stun frames could be greater than zero and so if they are for any reason we want to just decrement from them every frame this is just going to subtract one remember tick is called every single frame so we have 300 frames in five seconds this is going to get called 300 times within five seconds every time it's going to decrease the sun frames by one once it finally gets down to zero or less than that for any reason if this gets skipped always good to check less than or equal to zero that means we're ready to return back to idle we're done with our stun in this case we should set our block Shield durability back to the max block shell durability notice we never edited the max block shell variability this is a variable that's basically a constant right now we're not treating it like that but it's essentially a constant value we're not changing it anywhere so in which case we can set our current durability for the Box Shield back to the maximum and then we can reset our character State back to idle this means that everything is now back in the original state the stun is done the block is repaired and we are good to go we can continue with our game a few things we should do with this done here are make sure that we can't do certain actions while we're stunned so I'm going to scroll up to the top of the file and I'm just going to start going down every time we get to a function where we should not be able to do it while we're stunned I'm going to point it out so starting here at move right we shouldn't be able to move if our character is stunned now we already had an if check at the very top of this function if can move and if character State not equal to blocking we're going to just add another and and make sure that the character state is not equal to stunned if we're just doing this because if the character is done they shouldn't be able to move right now scrolling down to move right controller which is only different for if we're using actual game pads and not the keyboard we still had an if statement in here to make sure the character could move and the state wasn't equal to blocking same thing applies here we want to make sure our character state is not equal to stun as well now start jump is the same way we don't want to be able to jump if we're stunned character we were already checking if the character state was not equal to blocking and if the character state was not equal to dead I've also added in here character State not equal to stunned Additionally you probably should add if Ken move just like in move right because we probably don't want to be able to enable a jump if we can't move for any reason so even if we're not stunned if we're stuck due to not being able to move we should add Ken move in there so just adding that in there now now stop jump is a little strange because if I've started the jump then I don't have to worry about stop jump it'll work fine or if I haven't started the jump I don't have to worry about stop jump because it won't fire but that's not actually true stop jump just fires whenever you release the jump button in which case we should still account for it because actually it can affect things if we don't do this correctly so I'm gonna add if character State not equal to the character State stunned and I'm also going to add can move in here as well we may have to adjust it later in the future depending on how our jump logic works but honestly they should be matching right now because if a press doesn't fire but the release can fire it can mess up some of our logic with our jump or with our behavior in the future so just make them match even though they weren't before now start Crouch we didn't have anything for we had no if statement for so what I'm actually going to do is I'm going to copy the if statement from start and stop jump and I'm going to paste it in here and I am going to just Encompass the entire function we don't want to set the character to be crouching if they can't move or if they're stunned or if they're dead I am actually going to take out the blocking condition here because you may want to be able to go from blocking to crouch blocking if you have that in your game so you know potentially take out the blocking or leave it in it's okay either way I'm going to take it out in case we do decide to have blocking Crouch blocking be different so that way we can go from blocking to crouch blocking or Crouch blocking back to blocking so now this is what my if statement looks like if we can move and we're not stunned and we're not dead you could also add respawning in here if you want if this if statement doesn't return true we don't want to be able to set the character to crouching and we don't want them to be able to fall through one-way platforms so entire function encompassed and we're good to go now stop crouching really it should be the same thing like I said for stop jumping even though we didn't have it in here before I do recommend that we have these if statements and these conditions in here covering the entire function because otherwise when we release the Crouch button we can set this to be false but say we were stunned and we didn't want to stop crouching when we're stunned that would be allowed so we should check and make sure that these conditions are being met before we do any logic and stop Crouch as well now basic attack also same thing we can use the basic attack even if we're not in any of these states so I'm going to go to basic attack and I'm going to Encompass the entire function yet again in that if statement if Ken move and character state is not equal to stunned and character stays not equal to dead everything else in the function can remain the same and it will function exactly the same as we're used to just we can only call it if these things are true now basic smash attack the basic smash attack gets called if the character is holding the button and they release it so technically you don't have to worry about encompassing this one because we can't get to that state unless we go through basic attack for now we can leave this alone we may have to edit it in the future because there may be certain conditions where we can technically use or trigger a smash attack and we get canceled in this case we don't want to actually go and do this logic but for now it's safe to leave alone a special attack is basically just my second attack so I'm going to Encompass it within this if statement the same as I did basic attack special Health attack is the same as basic smash attack so we can ignore it for now we don't have to do anything with it now grab we should not be able to grab or pick up items while we're stunned so you know what we're gonna do we're gonna add that if statement around everything in this function and now grab has if Ken move character says done character state is not equal to dead encompassing everything that grab does at this point start blocking in this case we make sure that the character stays not equal dead or respawning we've been kind of leaving this one out of those above if statements but it's already in here so I'm going to leave it now I've added characters say is not equal to stunned as well if we're stunned we don't want to be able to start blocking stop blocking is actually okay to leave alone because we specifically check and make sure that we only return to the idle state if we were already in the blocking state this means if you're stunned you won't be in the blocking State and thus you won't be able to go to idle so actually we can leave stop blocking alone take damage handle launch reset damage counter debug take damage lose life respawn exit Revival platform break block shield and tick all can be left alone with all that done we can now load the engine and we don't have to do any blueprint changes today not even to the keyboard mode or anything like that that was all set up in the previous block episode so now we can come into our game our characters can do their thing fight each other and you will see the results that you would expect one thing I didn't show at the start of the episode that I am going to show now is the number of stun frames so if we go to our mannequin BP again and I'm going to type in stun frames you will see that the number of stun frames for breaking the block show is 300 and my current number seven frames to zero now I have one more durability because I've already hit my character twice I'm going to hit them a third time which is going to set them into the stunned State once they're in here we can watch the number of stun frames notice how it gets set to 300 and then every frame it is being updated thank you so much for watching I really hope this helped you with your game and with upgrading your block if it did Please Subscribe does more for myself in the series than anything else you can do and I just really appreciate it I want to give a huge shout out to my YouTube membership and patreon members and supporters once again thank you guys for all the love and support and for sticking with me through this fun journey I really appreciate it if you had any issues with this episode or any of my tutorials feel free to join the Discord Community I'd be happy to assist you and get you all sorted so you can continue with the series anyway guys like I said that's all I got so thank you so much for watching I'm Sean the bro and I'll see in the next one goodbye guys [Music] [Music] thank you
Info
Channel: Shawnthebro
Views: 411
Rating: undefined out of 5
Keywords: Shawn, the, bro, Shawn the bro, video, game, video game, stb, how to make a super smash bros game, unreal engine 4, ue4, unreal engine, unreal, engine, tutorial, super smash bros unreal, super, smash, super smash bros tutorial, ue4 super smash bros, super smash bros unreal engine, bros, fighter, platform fighter, platform, ue4 platform fighter, brothers, unreal engine 5, unreal 5, ue5, c++, blocking, block, shielding, shield, counter, parry, hitbox, collision, hit box, hit, box, hit bubble, bubble, collide, hi
Id: rUpABTfXnLM
Channel Id: undefined
Length: 24min 51sec (1491 seconds)
Published: Fri Mar 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.