How To Create Fall Damage In Unreal Engine 5 (Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another unreal engine 5 tutorial so in today's video what we're going to be going over is creating up a full damage system in which this will actually damage and kill the player as well so what we're going to be doing is using a system which we've already created previously of actually damaging and healing the player so you don't technically need to follow that to do this however it is very beneficial and i'll leave a link to that description down below but let me hit play and show you what we're going to make today so if i were to just jump what you'll notice is my health doesn't go down let me just heal the player very quickly like so so we're at full health if i just jump from this height maybe what we should do is have a tiny bit of damage so not too much if you jump higher we'll do more damage and so on and so forth you obviously know how full damage system works but i'm just showing it in this case as well and this is very easy to customize and set up so you can change how far you have to fall to do a certain amount of damage and how much damage each fall will do as well so for example if i were to fall from all the way up here this should kill the player like so and so i did heal a tiny bit before i went up as well just to show you it working and i've kind of slightly disabled the death system just don't continue walking about and showing off like so but you get the idea obviously again you know what a full damage system is so without further ado let me delete this code and i'll show you how i've done it so the first thing we want to do is we want to open up our character blueprint so for me that's going to be control space to open the content browser content third person blueprints bp third person character and this is the only place we're going to be doing code so again like i mentioned earlier we've already got our damage system set up here and our healing and all that good stuff like so so what we're going to do is create a variable first before we do anything else naming this tmp dmg or temp damage or temporary damage whatever you want to name it and this is just going to help with the calculations of our damage on our full damage system i'm going to change this from a boolean to be a float like so compiling and saving that then in some empty space on our event graph we want to right click and get event on movement mode changed perfectly like so so what we're going to do is out of new movement mode we're going to get an equal equal nm like so setting this to be falling so if our new movement mode is falling and hold down b left click to get a branch connecting that into there like so then out of true of this we want to start calculating our full damage so we're going to go all the way up here out to true to give us plenty of space and get a re-triggerable delay like so it wants to be retriggerable so that if we fall a small amount and then start falling again it's going to restart immediately it's not going to have to wait for the whole system to end it will restart because it's retriggable to re-trigger the delay in this duration we want to set it up so the shortest amount of time the player has to fall before it starts giving them damage so for me i'm going to put this as one second as for my character this is the perfect amount of time for them to be able to jump and fall from a small height without it needing to do any damage again this might be different for you if you've changed about the gravity or the jump velocity or anything along those lines or you might just want it to be higher if you wanted so this is what i'm gonna have it as being one after completed we're gonna hold down b left click to get a branch like so connecting it up there with the condition of this being getting the character movement out of this doing is falling like so connecting that straight into the branch there like so and the reason we're doing this is because obviously once this delay finishes we want to make sure the player is still falling not they've started and now they've stopped because if they have stopped we obviously don't want to increase the amount of damage or in this case damage them so at false we're not going to do anything out of true we want to hold alt and drag in our temp damage variable we created earlier so to set the temporary damage first of all i'm gonna set it to five so the lowest amount of damage it will deal is going to be five again you can obviously change this for you but that's going to be perfect for me then what i'm going to do is select the delay and the branch and the set damage control c control v to duplicate it just underneath it like so with the set temp damage going into the new re-triggerable delay like so i'm also going to double click the execution line to get some root notes just to keep it looking nice and organized and make sure that i've connected in the earth falling into that branch as well so now everything here is good we obviously just need to make sure we change the delay and the temp damage as well so how i'm doing it is the delay is going to now be 0.25 now you can obviously change this photo if you want again it just means the lower this number the quicker it's going to be between each damage increase the bigger the number the lower b so the longer and higher the player has to fall so again obviously this will just be customizable for you what you can do is also just go into a level and just start falling from different heights and timing it so jump from a place where you wanted to do a certain amount of damage see how long that takes and then put that duration in here obviously you're counting this so if it's going to take two seconds you'd want this one as one because that's one as well so i hope that will make sense then we just want to duplicate this again so i'm now going to duplicate the top one again like so including the earth falling and the character movement here control c control v down here like so once again connecting this up as we just did before i'm going to move this up a little bit as well like so the delay for this one i'm going to again have a 0.25 and i also forgot to change the damage last time sorry so i want to change the damage of this one to 20 i'm increasing it quite a bit then for this one i'm going to go to 40 perfectly like so then i'm going to duplicate it one final time like this we'll just move this down connect it all up like so as we have here this duration of the delay i'm gonna have as point one instead and the damage to be one hundred so this one here is going to fully kill the player so if the player's been falling for over a second it will be five damage over 1.25 seconds it'll be 20 damage over 1.5 seconds it'll be 40 damage and over 1.6 seconds it'll be 100 damage so kill them instantly so what you can also do here is just do the max health if you want to make sure that always kills them but i don't want to do that i just want to have it as a hundred so we compile and save that there and that is now going to be our system for calculating how much damage we should deal to the player again this is very easy to customize so you can add more of these on and do as many as you like change the duration of the delays and change the damage in the temp damage variable as well now what we need to do is actually deal this damage so what we're going to do is come down underneath the event on movement mode changed here right click and get event on landed so once the player actually lands from falling in here all we're going to do is simply apply damage with a damaged actor being get a reference to self as we obviously want to damage the player and the base damage is going to be our temporary damage which we've just created earlier very simple like that that's all we need to do and then after this we then want to make sure we set the temporary damage back down to zero so then when they next fall it will be restarting from the beginning again as you'd expect so let's compile save minimize this and hit play to test it out let me heal all the way up to full jump here we're not gonna take any damage if i had to jump from up at this height we should take a small amount like so that was five and if you jump from higher up we should deal more damage to the player like so and again and so on and so forth as you saw at the beginning of the video the higher we fall from the more damage we're going to deal and again you can set up how you like perfectly like this and there are different ways of doing this system so for example when i did it in ue4 i did it based on speed rather than how long you've been falling for different games do it different ways it's really just up to personal preference of which you prefer and i decided to do it this way in ue5 like so so i think that'll be it for this video as we've done everything we want to do what we've done is we've set up a full damage system in which we can deal damage to the player using a previous system we set up of dealing damage and healing the player so once they've been falling for a certain amount of time from a certain height so on and so forth we're going to be doing a certain amount of damage perfectly like so however you did just see there obviously if we then do kind of get stuck somewhere and fall down slowly as you saw it's going to then do damage which is why you sometimes might prefer doing the speed version instead of the falling version as it's then based on how fast you're going not how long you've been in the air again it's just different versions and i'll leave a link in the description down below to the speed version instead of the delay version so thanks so much for watching this video i hope you enjoyed it and i hope you found it helpful and if you did make sure to like subscribe down below so thanks so much for watching and i'll see you in the next one [Music]
Info
Channel: Matt Aspland
Views: 9,901
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, games design, ue5, unreal engine 5, unreal engine 5 tutorial, ue5 tutorial, fall damage, damage, system, health, fall, falling, fell, off, of, cliff, death, height, heights, die, dead, kills, take, take damage, deal, falling down, down, up, fast, quick, quickly, easy, basic, advanced, ue5 fall damage, ue5 kill player
Id: pw0W3nLatA8
Channel Id: undefined
Length: 9min 6sec (546 seconds)
Published: Thu Jun 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.