How To Create Fall Damage | Unreal Engine Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
to add fall damage you want to open up your character right so somewhere over here in the empty space right click and do event on landed right click once more and do add custom event and call this fall damage and then call this fall damage custom event right here on this event on landed the reason I'm separating them like this is because fall damage is going to have a bunch of stuff in it that we won't we don't want to get jumbled up with the on landed stuff next you want to drag out your character movement right here and drag off of character movement and search for is falling right here hold down B and left click to add a branch connect this to there and connect this to there and next I'm going to create a function right here and I'm going to call this calculate distance and over here in category instead of having it default I'm going to do B damage and as you notice right over here it's in its own little category this is just so it doesn't get mixed up with other functions and I'm going to select this function to be pure as well and I'm going to add a input I'm going to call this distance and make sure you set this to a float and so now I'm going to right click and search for get velocity because we are going to to calculate the distance by how fast we're traveling when we hit the ground we don't need all the axises so or axes so right click it split strike pin and all we need to use is the Z since we are falling down and we want to calculate how high up we were we need to multiply this Z value by1 and then off of this ne1 we're going to do is great then and then this is where we are going to plug in our distance just like that or you can actually disconnect this and right click and search for distance get distance and you can plug that in like that and over here for the output we are going to drag off of this and this is going to need to be a Boolean and just name this true or you could name it something like decision would probably be a little bit better and then hook this into there and then compile and Save all right and so back over here in the event graph we can drag out our calculate distance and as you can see this function looks exactly like this one and in case you didn't know this is what a pure function is it doesn't need an execute line it can just do everything straight through without nothing executing in it and the reason why I made this a pure function is because if you want multiple fall damage thresholds then this adds the value for that so I can drag in like four of these I could drag in five of them for the sake of the tutorial I'm going to do three it's just a big fall damage medium fall damage and small fall damage I'm going to set this top one to about 1,000 on the distance and then the medium, 15500 and the third one to about 2,000 something like that I'm going to hold down B again and drag in another branch connect this to true and we are going to make the decision for our first calculate distance so connect that right into there and I'm going to do the same thing for all of these so hold down B and press two more times connect this into true and then connect this one up and once again connect this one into true and connect this one up so now to calculate the actual fall damage and apply it and I'm going to make one more function as well and I'm going to call this one calcuate damage and once again I'm going to set add this to the fall damage category you can just drag it in there but this one will not be a pure function we can have this variable be an input on the function right here so just call this variable or call this input fall damage and inside of here you want to drag off of your execute pin and apply d damage the damaged actor is going to be this a reference to herself the character the base damage is going to be fall damage the event instigator is going to be our player controller so drag off and do get player controller and our damage causer is going to once again be self you can either connect it up or copy and paste a new one and the damage type class you don't have to worry about that and now if you follow my tutorial this is where you can plug in your health variable right here but just for the tutorial I'm just going to make a simple float and call this health I'm going to compile so I can have access to this variable I'm going to set the health to one because you have to remember progress bars are on a scale of 0 to one so I'm just doing this for the sake of that and then you connect this health value right up to there and once again if you have a health system set up for my health tutorial then this value will work but for now I'm just going to come over onto event tick and I am just going to print string I'm going to grab the health get heal and connect this right up into string and also I may as well just go ahead and set this to 100 as well but keep in mind that if you do have the actual health value you may have to set it to one depending on if you divide inside the HUD or not inside the health wedget so then lastly we can hook up our calculate damage so for the first one since the calculate distance on the false will be less than 1,000 we don't want to apply damage but on the second one if it's less than 1500 then we come over here grab our calculate damage connect that up and this is where you can determine how much damage you want to apply I'm going to set it to about 10 for the small and then out here on this last one this top true one is the medium damage so I'm going to drag our calculate damage out once again and I'm going to set this to 20 and then I'm going to drag it out once more connect it up to the false which is the big damage and I'm going to set this to 30 compile and save and we can test out the fall damage system all right so testing out the system as you can see my health is over there on the left it's 100 and if I jump off of this and I hit the ground I fell from a high height and it set to 30 hold on I made a simple little mistake over here in the Cal calculate damage this apply damage right here instead of setting the health to that what you want to do is get your health like that and then subtract like that and then subtract the damage from your health instead of plugging it directly in there that was just my little mistake right there and see there's another mistake right there I had the calculate damage at the end swapped around so it was just showing 30 even though I was not that high up in the air so make sure you swap the 20 make sure the 30 or your highest value is on top and your lowest value is on bottom so now if we test this out from a low height right here I fall off as you can see I take 10 fall damage and as you can see from this height I fall off I take 20 damage I play again with the platform just a little bit higher I fall off and I take 30 damage but yeah that was a quick and simple fall damage tutorial if you enjoyed or found it useful leave a like subscribe for more and I will see you in the next one bye-bye
Info
Channel: The Average Dev
Views: 191
Rating: undefined out of 5
Keywords: unreal engine, ue5, ue4, unreal engine tutorial, ue5 tutorial, ue4 tutorial, ue tutorial, how to create fall damage, how to create fall damage in unreal engine, unreal engine fall damage, how to take fall damage in unreal engine, ue5 fall damage tutorial, ue4 fall damage tutorial, how to create fall damage unreal engine tutorial, ue5 how to create fall damage, ue4 how to create fall damage, unreal engine fall damage tutorial
Id: QaH7zqFuyvg
Channel Id: undefined
Length: 8min 39sec (519 seconds)
Published: Sat May 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.