How to Make a Run and Stamina System in Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys welcome to new analogy in five tutorial and today we are going to learn on how to make a simple sprint or run and stamina system so this video is gonna be very quick and easy to follow so let's get started so the first thing that we are going to do is go ahead and open the third person character blueprint or also it can be you know the first person blueprint or anything but i'm going to use the third person uh blueprint here so let's go and and you'll use find the spot nice clean spot and then we are just going to go ahead and type left shift because of course we want to run if we press the left shift of course it can be any lower key but i'm going to use the ships so what i'm going to do is just drag the character movement and what we're going to get from here is set max walk speed okay because from the character movement uh component we can basically have access into uh the maximum speed that our player can go right now the maximum speed is 500 so let's increase this to around 700 and then when it's released basically we're just gonna copy this and paste it here and the speed will go back into 500 i'm actually gonna set this value into a thousand to be able to see a better uh difference in the speed so we actually right now compounds have and press play right now i'm walking but i since i press shift you can see how quick i go and also the animations will increase great so now we actually have set up a uh sprint or a run system but of course now we need the stamina system in order to show how much we can run so for this what we're going to do is create a new variable and we're going to call it stamina and it's going to be a float because it's going to have decimals in it so we can be you know more precise so what we're going to do is just drag this in here i'm going to set stamina okay actually i'm going to be making an event so it's going to be cleaner so let's just go ahead and add a custom event and just say um choose stamina i don't think that's you know the best um you know name for it but anyway you know drain stamina could be also but i'm gonna use you stamina and basically we're going to set the stamina into new value so we're going to get our act through our current stamina and subtract by r1 for example okay and then this is going to be our new stamina also let's compile and then if we select our stamina variable we're going to set this to 100 ah for now and what i'm going to do is when i am basically pressing shift i'm going to make a retriggable delay and basically um the duration is going to be uh 0.2 is going to be right now so going to be good for now and then when it's completed well basically we're going to go ahead and do it again of course this will mean that it's gonna be kind of of a of a loop we'll resolve that in a second but anyway i'm just gonna go here do that so yeah so basically let's plug it and if we now compound save and we go into the use terminal here we're going to do is just print a string and it's i'm going to print the uh current uh stamina that we have so let's just go here and say use stamina there we go and then just play again and then if i press shift you can see up there how this stamina is actually draining however if now i just stop um it still continues because uh you know i i said that is a retricable delay so uh you know go again so what we are going to do is create a new variable and save it is running and of course this is going to be a boolean so um basically when we have uh press this i'm gonna just drag this and set it to be well it's running too and then in here we're gonna say that is running is false so now in here what we can do is just drag this and say branch and then ask if is running if it's running it will continue and then and it and if not it will break the loop so now if we go ahead start running you can see how this timing is raining but since we stopped you can see how it stopped and then we can continue great let's control one more thing and it's that in here just before the we print and you can drag this and then make a branch okay and i am going to ask stamina if uh it is less or equal than zero okay and so if it's false i'm gonna just continue printing so we can see and then if it's true so basically we don't have um we have serial stamina or less than zero so basically we should be we shouldn't be able to continue running so we're gonna do one thing you just basically set is running to be false and then again to get our character movement and our uh set maximum speed and basically i'm just going to plug this in here and then it's going to be left to 500 i'm gonna i'm going to also increase this into two the value that is and decreased so it can be a bit faster so right now i am actually running you can see that stamina is actually going ahead and decreasing and then when in a second i will get to zero you can see that i actually stopped running and then i mean i i cannot continue running because we haven't done that these seminar will actually go ahead and increase again so in order to do this what i'm going to do is go and create a new custom event which is going to be increase stamina oh sorry here we go and basically what i am going to do is go up here and then i am going to set the stamina okay and i'm gonna get the current stamina and add basically two and then this is gonna set the new stamina and then we are going to make the same thing here so we're gonna make a branch and we are going to ask if the stamina their current stamina is basically now greater or equal this time instead of less on equal it's going to be greater and then uh basically a hundred which is our maximum stamina that we are allowed and so if it's true we are going to uh stop adding i'm just gonna go ahead and create a new variable called can increase stamina it's gonna be boolean 2 and i'm going to say set it's going to be no i cannot increase stamina by default it's going to be true so compound ticket and then before here i'm just gonna make a branch and it can increase stamina we're going to ask so if we can i will continue and if not not and then in the false we are going to enable this great so it will increase uh but of course we need to call this function so if we are not running we are going to call increase stamina but it has to be also a reachable delay so let's go ahead and just drag this here and then we're going to make the same question that if uh we can increase tana and boom and then if it's true we are gonna go back into here there we go so we actually don't have to control it on here sorry because we are going to control it up there so we're just gonna delete that real quick now in order to uh basically see your stamina better what i'm going to do is just create a slider so i'm just going to go here content and i'm going to create a new folder call it ui all right let's enter and i am going to create a user interface and a widget blueprint okay it's going to be a user uh widget it can be called we be um stamina okay can be called whatever you like it can be you know the whole hot for your game et cetera so let's go ahead and open it um and ruin gm5 has this thing where it doesn't create a canvas so you just type canvas and drag it in here so there we go is needed and then use a progress bar i just drag it into the middle resize a bit and then drag it back a bit uh down here uh it's going to be uh blue for now and then the percent and here in the progress section you're going to say bind and then create binding and it will uh bring us here so when we get the percent we're going to cast to our third person bb third person character this is gonna be get player sorry player character and then in here we are going to get stamina and then we are going to divide this by our max stamina which is of course a hundred and then this is going to return our value so if we go back into the third person character real quick and go into the begin uh play event just add it over here go up and say uh create widget okay and then in here we're going to uh select our wii p stamina owning player is going to be get on in player or get play controller whatever you want to call it and then return value it's gonna be add to viewport there we go and then compile save okay sorry we gonna use get on player get player controller sorry that was my mistake so if now we press play you can see down then that we actually have a progress bar and then if we start running the seminar will decrease we stop it will increase and then we can continue running and then there will be a point where it actually will get to zero and we will stop and then if i stop it will continue increasing and i can go through and running and that's it guys really easy right so if you have a video please like subscribe and comment any more arnold gm5 tutorials that you want to see in this channel and with all that said bye bye you
Info
Channel: Gorka Games
Views: 52,220
Rating: undefined out of 5
Keywords: games, videojuegos, unreal engine, unreal engine 5, ue5, run and stamina, tutorial, quixel, megascans, unreal engine tutorial, how to maek a run and stamina system, ue5 how to make run and stamina system, ue5 how to make sprint and stamina system, unreal engine run and stamina system, unreal engine 5 how to make sprint and stamina system, unreal engine 5 stamina, unreal engine run, unreal engine 5 sprint, unreal engine 4 run and stamina, unreal engine 4, ue4, ue5 run stamina
Id: jtJddy6zgqA
Channel Id: undefined
Length: 13min 10sec (790 seconds)
Published: Sat Jul 16 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.