Sprinting With Stamina Bar Tutorial Unreal Engine 4

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi in this video we'll be going over how to create a stamina system which depletes when it's used and it will automatically recover when we're not using it so if we just hop into the third person character finds in space we're going to create some new variables so you click add variable and i'm just going to call this stamina and we're going to change this to a float so it could be a number and this is where we're going to consume our stamina so i'm going to make it the left shift key and when we press this it's going to consume our stamina so in order for us to start sprinting we're going to get our stamina and if our stamina is greater than 10 it's going to allow our character to sprint so i'm just going to put 10 and i'm going to create a branch and when i stamina is greater than 10 we're going to make it so our character can sprint so it will get character movement and set his walking story and set his walking speed max walk speed and i'm going to set it to a thousand so i can't be much moving much faster when he is sprinting and then we're going to create a new variable called uh stamina on and it's going to be a boolean and this will just start consuming our stamina so if you drag this on and connect that up then if we just uh copy this and control c control v and then just plug this in so when we release shift it's gonna set our walking speed back to the default which is 600 and uh we'll need to take on the stamina on bar here so it just consumes us down we'll reference this later so next what we're going to do we're going to get event tick as every second we're going to be filling our stamina bar when our character is not running so when i create a branch and the condition is stamina on and when our stamina is on it's going to start to consume our character stamina so if we get our stamina and if we uh minus float and i'm going to minus it by naught point seven i find this is a nice value around this around later and we're gonna clamp it as we as i want my seven bar to only go from zero to a hundred so its max value will be a hundred so i'm just gonna clamp it there and then if we drag this on and set the stamina i just plug this in so when our standards on it's just gonna consume our stamina um we're just gonna control c all of this control v so when we're not running and sprinting it's going to start to restock our stamina we just plug that in and where the minus is we're just going to delete this and add float and i'm just going to make this 0.1 sorry 0.4 so it consumes so it adds a bit slower than we can consume it and we just compile this so it saves so next i'm going to drag a sequence so when we're running in case in case we run out of stamina when we're running we want our character to go back to his default speed so this is just what this sequence is for so if we drag this on and have a branch so while we're running if our stamina ever gets less than 10 we're going to make it so our character just returns back to his normal walking his default running speed state so if we find the character movement and just set max walk speed and we'll just say it 600. and now we've got our stamina so we're just going to make it so that we can see this visually so we go to user interface and create a widget blueprint and we're just going to call it stamina ui what we want to drag is a progress bar and i'll just make a big size and correct and we're going to bind this to our stamina in our third person character so we click the bind key and then we're going to cast to our third person character and as the object we're gonna get the player character and as the third person character we're gonna reference the stamina so we get the stamina and then we're gonna need to divide this by a hundred as um the progress bar only goes from zero to one so we divide it by a hundred and we just compile and uh i mean i need to set the standard so zero is fine if we just click play i forgot to attach the hard so we can see it so we go to event begin play so we can just see the hud and create widget and we just like the stamina ui and then if we add this to the viewport it should be obviously our stamina just increase so you can see our standard bar increase and when we hold shift we run faster and it depletes and then we're out it goes back to another speed so you can play around with the valleys so you can adjust this down another but that's all thanks for watching and i'll see you next time bye
Info
Channel: Unreal University
Views: 27,785
Rating: undefined out of 5
Keywords: unreal, engine, tutorial, ue4, learning
Id: 9ycYrJU0H98
Channel Id: undefined
Length: 5min 51sec (351 seconds)
Published: Fri Jul 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.