First Person Crouch Unreal Engine (UE4 & UE5) - With Bonus Feature

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to another 3d ross video today i'll be showing you how to create a crouch function for the first person player in ue4 and if you stick around to the end i'll show you how you can incorporate a cool sneak vignette like you can see here so let's get going but first make sure you smash the like button if you'd like more tutorials like this and make sure to subscribe and enable the notification bell to support the channel for free and get notified whenever a new video is posted many thanks and enjoy the video to start creating this crouch effect i'm going to use the first person example template as the base so with the character selected i'm going to go edit blueprint open blueprint and i'm going to find some space in the event graph so to crouch i'm going to want to press ctrl to crouch so i'm going to right click and type in ctrl and i'm going to use the left ctrl so when we press we want a crouch and when we release we want to stand back up again so to drive our crouching i'm going to use the capsule component this is basically our clear collider this is controlled by the half height so as you see when i reduce it it gets smaller and when i make it bigger it gets taller so that is going to be used to drive our crouching like this i'm going to reset it back to the default of 96 and we'll come to that in a moment so because we're using the capsule component i'm just going to left click and drag it into our event graph and then off that pin i'm going to type in set capsule half height because that is the value we want to control for our crouching and then we're going to set the half height here so i'm just going to create a variable to control this and i'm just going to call it half height and i'm going to call it offset and you'll see why i'm doing that in a moment instead of directly setting the height i'm going to create an offset and you'll see why i'll do that in a minute but it's mainly just to make it smoother and i'm going to change the variable type to a float hit compile and there we go we have a half height offset here so i've just made the default as 40 but you can make it whatever you like how much you want to reduce the half height by so that can go into here and we're going to get the half height so we can just plug this into here for test now so when you press left ctrl we're going to change the half height to 40 instead of 96. so if we compile and save that and we play the game and i press crouch as you can see we just crouched down and now we can get under these boxes but as you can see we're no longer standing back up and that was quite jerky so we're going to fix that right now so going back into the event graph i'm just going to make some more room and i'm going to create a timeline so i like to use timelines for anything that's interpolation based that i want to move smoothly from one value to another so i'm going to type in timeline and add a timeline and i'm just going to call this timeline crouch height and then when left control is pressed we're going to play but i'm going to do a play from start i'm just going to do that so we don't get any weirdness of it not completing and then the values getting added up and up and that way we can end up sinking further into the ground or flying further up into the air because the values don't get a finish but that'll become more obvious if you experiment around so and then on release i'm going to reverse but i'm going to reverse from end for the exact same reasons and then on update i'm going to set the capsule half height so to do this smoothly i'm going to control the half height through the timeline so to do that i'm going to open the timeline by double clicking it and i'm going to create a float track and this is just going to interpolate between value to another so i'm going to name this track up here i'm just going to name this offset value and the length i'm just going to set as 0.2 so if we shift left click now we create a point in our graph this keyframe is going to start on zero so i'm gonna set time to zero i'm gonna set the value to zero now normally people would set this to say 96 because that was our default capsule and then interpolate or whatever value they want but i'm going to do this a different way and you'll see how i'm doing that in a moment but i'm just doing it this way to keep things more consistent and easier as your code builds up so again i'm going to shift left click and create another keyframe and this one's going to be at the end of our graph so at 0.2 seconds and i'm going to set this value to 1. now if we go back to the event graph we have this offset value which is that track we just created now if you plug that straight into here that would change the offset height from 0 to 1 because i'll interpolate through it and i'm not going to do it this way because i want more flexibility and keep things more consistent so i'm going to use this height offset that i created so what i'm going to do here is i'm going to take the offset value and i'm going to multiply it so if we type multiply float by float and i'm going to multiply it by our height offset value so what this does is when this has at 0 then our half height offset will also be 0 when this is finished on the timeline so 1 then this half height offset will be at 40 and when it's halfway through at 0.5 this value is going to be at 20. that way it slowly builds up this value and what i'm going to do now is i'm going to take this output and i'm going to minus it so float minus float i'm going to set it to the bottom pin because our top pin is going to be the 96 which is the value of our half height currently so it takes our current half height and it minuses it by our offset value but in slow increments as defined by the timeline so if you want to set this for consistency in the project then you could create an event play and set a variable equal to our capsule component that way you've got this value and you don't have it hard coded and have to change this each time this changes but i'm just going to hard code it in for now and i'm just going to plug this into the half height so if i compile and save this now i'm just going to run through it so when we press ctrl it's going to go from zero to one so this is going to go from 0 to 40 and we're going to minus incrementally 0 1 2 3 4 off 96 so that's going to lower 96 by 40 and then when we release it's going to reverse that so if i compile and save and just play it now when we press ctrl and hold it down we're now crouching and when i release when i stand up control a crouch and release the stand up so now that's working we can get to the bonus round of this video so that is the vignette effect so to do this vignette effect i'm going to use the timeline again and i'm just going to use this value but you might want to create your own value or multiply it like i have here but i'm just going to use this value just straight out so to do the vignette effect i'm going to get the first person camera so i'm going to left click drag this in and i'm going to change the post processing effect of this camera so to do that i'm just going to left click drag and i'm going to type in set post process and i'm going to set post process settings now i'm going to get a node and it's the make post process settings node and we're going to change the settings in this node and set it equal to the settings of our camera so any changes we make here is going to be reflected inside our camera and in this node the setting we want to change is the vignette so i'm going to type in vig and as you can see vignette intensity under the lens image effects and i'm just going to tick this and now we have a vineyard intensity multiplier here so to control that i'm just going to use the offset value so when we're crouching it's going to be 0 and sorry when we're not crouching it's going to be zero and as we start a crouch it's going to move up to one and then when we stand up it's going to slowly go back down to zero and if we pull out the pins from set and connect it to the capsule half height we now connect that together so now if we compile and save and we go into the map and i press control we've got that vignette and when i let go we no longer have it so as we crouch vignette we stand up non crouch vignette stand up none so this could be cool for like a sneaking effect or things of that nature so yeah you can also add this on to anything else you want i think that's really handy that you can control the post processing effects of the camera within the editor and of course you can use the multiply i did here so you can multiply that by 50 if you want uh 50 intensity on your vignette uh just as an extreme example but you don't need a value between 0 and 1 you can do whatever you like just like i did here but yeah that kind of concludes this tutorial um you can use this post-processing effect say for like a zoom effect when you want to zoom in say with a gun and dock in your surroundings a field of view to focus in and you can find a tutorial like that linked at the end of this video but yeah check out my other videos if you're in unreal engine or creating art you might find them some of them helpful if you found this video helpful do give it a like it helps me out a lot and subscribe and turn on the notification bell it is free and again it helps me out a lot and you'll get notified when a new video is up if you found this video helpful please let me know down in the comments or if you have any issues just let me know what your issue is down in the comments and i will help you as soon as possible um but yeah if you found this helpful please do give it a like consider subscribing and i will see you in the next video thank you and goodbye [Music] you
Info
Channel: 3D Ross
Views: 3,882
Rating: undefined out of 5
Keywords:
Id: KI-zsgcrJ80
Channel Id: undefined
Length: 12min 46sec (766 seconds)
Published: Fri Apr 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.