How To Make A Third Person Shooter - Unreal Engine 5 Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys mizo frizzo here and in this Unreal Engine 5 tutorial I'm going to show you how to set up a third person shooter so if you're fairly new to Unreal Engine 5 and you're wondering how can I make a shooter game in Unreal Engine 5 I'm going to show you in just about 1 hour how to set up the Bare Essentials of a third person shooter so we're going to be doing everything from Locomotion to aiming down the sights and crouching we're going to have some very B basic fully automatic firing logic that's going to cause damage to this enemy and if their health gets to zero they are going to rag doll on the floor like so now before we get started guys if you haven't already if you find this tutorial of any use or value whatsoever please hit like And subscribe and feel free to make a donation to the channel FYI I have set up a patreon the patreon does not give you any added benefits it is rather just a way of people uh donating to the channel without so much of their money going to YouTube YouTube takes 50% if you make a donation via YouTube YouTube takes 50% so patreon is just a way of more of your making more of your donation um sort of go towards helping me make more tutorials you'll also find a link to a Facebook group called mizo frizo tutorial discussions in the description and a subred called misof frizo tutorials these are places where you guys can share what you've made and reach out to the community and you know help debug any problems that you may have created as a result of following my tutorials I'm sure there is one or two um so without further Ado guys let me show you how to do this all righty guys so the first thing I'm going to do is create a new project using the third person template I'm just going to rename it we do not need starter content or Ray tracing or C++ and and hit create and the first thing I'm going to do once the editor has fired up is open up the unreal Marketplace to download some free asset packs so head on over to the unreal Marketplace and the first one we're looking for is this one it's called the animation starter pack it's by epic games themselves hit add to project and if you don't see your project here just click show all projects and find your project and then down here select the most recent compatible version which is probably going to be 5.2 and hit add to project and the next ones I want you to find are these military weapons Dark and military weapons silver you can just search for military weapons and filter for free and they should pop right up if these are not free in your country I don't know what to tell you um they should be free you can get either either one of these or both um I'm just going to download the military weapons Dark so I'll hit add add to project and if your project is not here you can search for your project click show all projects select your project and then down here select the most recent compatible version which is probably going to be 4.27 and hit add to project you'll know these have added because you'll now have these folders anom starter pack and also military web dark so the first thing we're going to do is head into the anim starter pack and we're going to retarget these animations for the U 5 mannequin so I'm going to right click in here and create a new folder just call it ue5 and then I'm going to filter for animation sequence if you don't have this filter here just click this little one here and find animation and animation sequence and filter for animation sequence and then you can click in here and press contrl a to select all of these and if you're in 5.4 this will be super easy you just right click and go to retarget and animations and then once this little window pops up you choose your target skeletal mesh which we are going to be using many today so I'm going to select skm many and click in here press contrl a to select all of these hit export animations I'm going to find this new folder we created ue5 and I'm just going to add a prefix uh ue5 uncore so these will be prefixed with uie 5core at the beginning of their name here hit export and leave this as default and hit export should take you to the folder where they've been duplicated and retargeted into and there you'll see we've got a bunch of these animations retargeted onto the ue5 skeleton very nice and very very quickly guys for anyone who's using 5.3 or older I will show you how to retarget these animations in the older versions of the engine so I'm going to right click here and add that new folder U 5 I'm going to filter for animation sequence if you don't have this here just click right here animation animation sequence to find this filter now that I've filtered for animation sequence I going to crol a in here and then I'm going to right click and go to retarget animation assets duplicate and retarget animation assets SL Blueprints and then I'm going to find the I retargeter RTG ue4 manyi to ue5 manyu this comes as part part of the third person content pack so I can select that retargeter I can change the folder right here to anom starter pack in ue5 and add that prefix u5 uncore and hit retarget and there you have it guys for anyone using Unreal Engine 5.3 or older that is how you retarget the assets onto the u5 mannequin the next thing I want to do guys is open up the third person character blueprint so if you look for this third person folder and blueprints and BP third person character and open this up we're going to make this act a little bit more like a third person shooter because if we hit play now you'll see that the character kind of can run around any direction and we can't aim or anything like that so let's change the settings a little bit here if we go into our BP third person character and search for Orient and uncheck this Orient rotation to Movement we can also search for your and check use controller rotation your to be true and now you'll see if we hit play we can now rotate our character they're always facing the direction of the camera and when we run to the side they're not rotating at all they're just looking straight ahead let's also change the camera boom setup so we've got a little bit of over the-shoulder action so I'm going to go to the camera boom here just get rid of this search and down here you'll find socket offset and Target arm length so if we change Target arm length to 300 and if we change these to 0 75 and say 75 actually let's make this second one 100 you can see now that the camera is moved over to the right a little bit while we're here I'm also going to change the transform on the camera boom here this third transform to just an even 10 because we're going to change this when we Crouch we're going to move our camera up and down so now if I hit play you'll see that the camera is sort of over the shoulder a little bit up a little bit higher and a little bit closer to the character very nice okay let's start working on the animation blueprint and we can find the animation blueprint by going back to our characters blueprint right here and if we select the mesh here in the viewport or over here in the components tab over here you'll see animation mode use animation blueprint and anim class is set to ABP Quinn now ABP Quinn if we just hit browse here it will take us to the animation blueprints anim um ABP Quinn is a child of ABP many uh so we are just going to use ABP many today so back in your character is blueprint if you would like to change the skeletal mesh asset to skm many and change the anom class to AB Manny we can then browse to ABP Manny and open it up and straight away we're going to make a couple of changes in here to make this work a bit better with our third person character so this cast here on event blueprint initialize animation is just a cast to the character class of which the third person character is a child so this isn't a direct reference to our third person character so we're going to change it to one right now by deleting this node drag off of get owning actor here and find third person character cast to BP third person character plug this in here and then select this set variable node here and over here in the details pane change the variable type to bp3 person character object reference give you this warning just hit change variable type close this and now this character reference here is a direct reference to our character um one of the things we need to set up in here is the um the variable that tells the animation blueprint which direction our character is moving so that we've got a bit of directional movement so what I'm going to do is grab this first box here move it up a little bit and create a bit more space and then I'm going to grab my character reference from down here get character and what we can do is get actor rotation and then off of get actor rotation we can find calculate direction it'll be the second one here velocity we can plug in the velocity right here and and then drag off of the return value here and promote to variable we can call this direction plug this in at the end here and now we have access to our Direction like so all righty uh now we can head over to the enm graph and start making a few changes in here the first thing I'm going to do is delete this control rig because any animations that we change are going to mess up the foot ik so we're just going to get rid of that foot ik node there and I'm going to move this slot default slot out here move main states up here and with main State selected I'm just going to contrl C the name from the details panel over here and drag off of here and find new save cached pose I'm going to paste in that name and now that we've cached this state machine here we now can bring it up anywhere we want so this basically saves this pose um and then we can place it wherever we want in the graph so I can right click down here now and type main states and use cached pose main states like so um what we're going to do is uh find a layered blend per bone whoops layered blend per bone and this is going to allow us to blend different animations on the lower body and the upper body so our legs can be walking and running and jumping and whatnot and our upper body is going to be holding a gun so main states will go into base pose you can plug this slot default slot into the blend pose here and if we select that layered blend per bone over here in the blend mode setup we can drop down layer setup and index and add a branch filter drop down the index on that Branch filter and change the bone name to spine 01 and make sure you check mesh space rotation blend and mesh space scale blend and one other thing we can do while we're here is I'm going to add an uh vertical aim offset a sort of procedural vertical aim offset to our character so he's a posing right now I'm just going to plug main states in into the output pose here so I can demonstrate what I'm talking about so right now if we look up and down our character is not looking up or down at all he's just in that idle animation so what we're going to do is use the cameras rotation to rotate the spine bones of this character we can right click here and search for mod and select transform modify bone uh I'm just going to connect main states back into the base post there if we select this transform modify bone we don't need all these pins here we only need rotation so what we can do over here under translation on this little pin drop down we can uncheck expose as pin and we can also do that with scale and Alpha un expose that as a pin so we've just got this one pin rotation but over here we want to change the rotation mode to add to existing like so so there's just one pin rotation and the rotation mode is set to add to existing now that we've done that we can duplicate this four times by pressing contrl D or pressing contrl C and then contrl V so that we've got five of these and then what we can do is Select each one and change the bone to modify so we're going to change the first On's bone to modify to spine one the second one to spine two third one to spine three fourth one to spine four and spine five we can plug this execution pin into the first one and I'm just going to place this like this and I'm going to plug each output into the input of the next one like so and then the last one into the output pose but the last thing that this needs is a rotator to plug into these pins right here so how we can do that is we can head back to the event graph and I'm just going to very quickly tidy this up by selecting these comment sections and selecting the first few words in the comment text up here control seeing that and then I'm going to highlight all of this and right click and select collapse nodes can paste in those words there set velocity and ground speed like so and I'm going to do that with each one of these so I'm going to contrl C set should move select all of this right click collapse nodes contrl + V set should move and set is falling crl C collapse nodes contrl V and now this is much tidier I can add an execution pin here and I'm going to grab my character reference over here and get my character reference I can drag off of this and get base aim rotation I'm going to split right click on this pin here and split the struct pin into our X Y and Z values this y value is the up and down movement uh up and down look of our camera and what I need to do now is inverse this and also divide it by five because I'm applying it to five spine bones so I'm actually going to divide it by5 -5 so I'm inversing it um because when we look up it's kind of negative and when we look down it's positive so we need to inverse it here and then I can make a rotator leave that plugged into the X right there I can drag off the return value of that make Rotator and promote to variable and let's just call this pitch Rotator I can then and plug this in here and I might just copy pitch Rotator there and select all this collapse nodes and call this set pitch Rotator like so now if we go back to our anom graph we can get this pitch Rotator and we can plug it in to each of these rotation pins and he's deposing here because we haven't plugged anything into the blend poses so this layered blend per bone is blending from the first spine bone up and because it has nothing to blend he's just doing the standard a pose there but you should still be able to see the vertical aim offset in action there so he's looking up and down now because the spine bones are rotating okay let's get those upper body animations set up what we can do is just copy this Locomotion uh State machine right here by pressing controll D and then I'm going to rename it up here and call it upper body anims I'm also going to contrl C that name drag off of here and find new save cached pose paste in the name and now we can call upper body anoms down here use cached pose upper body anims plug that in and now we can alter this state machine and whatever we put in here will be played on the upper body so we can open up this and we can go to idle and I'm just going to delete this mm idle and I'm going to find idle rifle where is it ue5 idle rifle hip and plug this in here and make sure you check Loop animation this animation will Loop while he's idle and go into walk/run and if we go down here and just clear this search for idle and find ue5 blend space jog we can plug this in here ground speed will go into speed and that direction variable that we've created is right here we can grab that and plug it into Direction and now we've got very basic setup here with our walking around and whatnot uh we can also add that blend space into our um our lower body animations our Locomotion State machine right here so let's go into idle and let's replace mm idle with idle rifle hip make sure you check Loop animation and let's actually just go into our upper body anims walk run and let's just contrl C all of this stuff here and go back out into our Locomotion into the walk run paste this in here and let's just use this blend space jog for the time being nice now we have some directional movement very good we just need to set up crouching and aiming and obviously attach a weapon to our character let's attach the weapon right now so let's go to our third person character here and add a new component it's going to be a skeletal mesh component I can call this weapon and make sure that it's a child of mesh you can tell it's a child of mesh because it's sort of indented a little bit here and if I click this drop down it's underneath mesh right here if it isn't you can just click it and drag it onto mesh so with that weapon selected I'm going to select a skeletal mesh asset for me I'm just going to use assault rifle B from that military weapons Dark pack and we need to create a socket for this to attach to so this needs to attach to his hand so we need to find his skeleton and create a socket in the skeleton how we can do that is we can select the mesh and over here in skeletal mesh asset we can click this little browse icon and browse to the skeletal mesh and you can see that the skeleton's here but just in case you're using some kind of other character you can open up that skeletal mesh and then up here you'll see a little skeleton button you can click that and it will open the skeleton like so but this is just the SK mannequin which is right here um we're using skm many so I'm going to change the preview mesh up here to skm many and I'm going to click this apply to asset so that it uh permanently applies this skeletal mesh to the skeleton asset right here I can also click preview animation and find idle rifle hip uh not that one idle rifle hip right here I can pause this and take it back to the first frame and I'm going to scroll down and find the right hand here right click on the right hand and add a socket I'm not going to rename this so I'm just going to leave it hand R socket I'm going to right click on hand our socket and add a preview asset and I'm going to add the assault rifle b as my preview asset right here so now we just want to put this into the right position it might help if you uncheck rotation snapping right here and we are going to put it into the right position particularly with regards to the right hand right here um but obviously the the front the left hand as well that's pretty good it doesn't need to be exact but in the right position like so I actually might just straighten this up a little bit and that'll do we can actually edit this pose a little bit so the fingers look a bit better um but for the purpose of this tutorial this is perfectly fine so now that we've done that we've created the socket and moved it into the right position we can go back to our third person character here and if we select the weapon mesh over here the parent socket we can change the hand R socket that we created and then zero out the location and the rotation right here so make sure this is all 0000000000 0 and the gun is in his hand like so very nice okay let's set up crouching and aiming so if we head over to the event graph and just head down here where we've got some empty space I just going to right click and find the c key I'm not going to be doing any enhanced input on this tutorial for the record any inputs in your game should be using enhanced input but I'm not going to set this up uh right now we're just going going to do a very quick and hacky way of testing this stuff out so we can just find the c key and the first thing I'm going to do is create a variable I'm going to call it crouching it's going to be of type Boolean I can hold alt and click and drag this out to get a set node and then contrl D to duplicate it and I'm going to hook these up and on pressed I'm going to set crouching to true and on false I'm going to set crouching to uh false like so sorry on released I'm going to say crouching to false um the next thing we can do is set the character movement speed so if we get the character movement here bring this out I can drag off of that and find set max walk speed and duplicate this down here make sure you plug the character movement into the target H up the execution pins and if we select the character movement here we can look over here for for what the default is and you can see here the max walks speed default is 500 so let's set it to 150 and then back to 500 upon release like so the other thing I want to do so we're going to set up the animations in a moment but the other thing I want to do is just drop the camera down a little bit when we Crouch so I'm going to do that using a timeline I can right click and add timeline and I'm just going to leave it called timeline plug this execution pin into play and this execution pin into reverse so what this is going to do is it's going to play a track that outputs a float a number um and when we release the key it's going to reverse it's going to play that in Reverse from the current position of that track so it's not going to play from the start start or reverse from the end it's going to play first time we do this play from start to finish and then upon release wherever it is it will just then reverse we can double click on this timeline and up here we can set the length of the timeline um I'm going to set it to 0.35 we want this to take a little bit of time we're going to make the aiming down the SES a bit snappier but let's set this to 0.35 and then add a float track we don't need to rename this if we hold shift and click twice on the float track it will add two of these key keys right here um and what we can do is we can set the time on the first one to zero and the value to 10 and select the second one and I'm going to set the time to the maximum time of this track which is 0.35 and set the value to 40 something like that if we click these two little icons here it will fit the graph to the screen and then we can scroll down and zoom out a little bit and then I'm going to select both of these points and then right click and select auto and you'll see that this has smoothed out this curve a little bit so as I said when we press the c key it's going to play this track and then when we release it it's going to reverse and play and reverse wherever we press and release the key um the reason this is 10 and this is -40 it's because if you recall uh we in our camera boomm uh settings we changed the relative transform to 10 here so this is going to move from 10 to -40 you see the camera boom is dropping down here so we're just changing the relative location of the camera birm from + 10 to -4 so we can go back to the event graph here we can find the camera boom and drag it out and we can off of that set relative location and I'm going to right click on this pin right here and split the struct pin and we're just going to plug this float track into uh this new location Z right here so it's going to change the uh relative location of the camera boom on the z-axis so up and down now we haven't added the animations yet but you'll see this at work if I press C it's dropping the camera down if I release it it's coming back up very nice nice and smooth that's good uh let's add the animations for this now so see we've created this Boolean and we've set it as true on pressed and false on released we just need access to this variable within our animation blueprint so if we go back to our animation blueprint back to the event graph grab the character reference and get crouching I can drag off of this and promote a variable leave it called crouching add a pin right here here and I am going to contrl C that and collapse nodes and just call this set crouching like so and now we have access to that crouching variable in our animation blueprint so what we can do is we can go back to our ANM graph and into Locomotion and in idle here what I'm going to do is find a node called blend poses by bu blend poses by bu and grab our crouching and plug it into the active value right here so if crouching is true it's going to play this pose and if crouching is false it's going to play this pose so we can plug our idle rifle hip into the false pose and if we find Crouch idle rifle hip and plug that into true and make sure you check Loop animation now if we're standing still he will Crouch I know it's a bit Snappy um I'm not going to go into making a smoother transition in this tutorial this is just a Bare Bones of setting up a third person shooter very very quickly so let's go back to the animation blueprint and go back out to Locomotion and the walk run and what we can do here is another blend poses by bull so actually I can go into my idol here and I can just copy this blend poses by bull with the crouching uh Boolean already plugged in go over to my walk run and paste this in and this jog will obviously be the false pose and then I can also grab my ui5 blend space Crouch walk a blend space with the Crouch walking animations plug this into true plug direction and speed in and now my character can Crouch and Crouch walk very nice now you notice a problem here if I crouch and move the upper body is trying to do something really funky I think it's trying to jog here so I'm going to change the upper body animations uh to the idle ones or at least at least just the walk because I think that's the jog so let's go to our anim graph and go into upper body anims and walk run here and yes it's doing the blend space jog here um we will actually just make this let's make it the walk forward no cuz those are iron SES um it will just have to be the idle rifle hip that's fine just check that that's a bit smoother now very nice and we got the camera dropping down when we Crouch very cool nice and we have the directional movement when we're crouching very good okay let's a uh add some aiming down the sight so if we go back to our third person character and just below the Crouch functionality here I'm going to right click and find right Mouse button and we actually are going to set the movement speed exactly the same so let's just duplicate this down here and I will also add a variable call it aiming and I'm going to drag this out and duplicate it plug these in like so and set it as true off of pressed and false off of released like so nice so that slows us down um but we also want to have a little bit of Zoom going on and we'll we'll reduce our field of view a little bit so we're going to add another timeline here add a timeline I'm not going to rename it I'm going to plug this one into play and this one into reverse and I'm going to open up that timeline and change the length to 0.1 so it's going to be a very Snappy ads indeed so 0.1 length of the track and I'm actually going to add two float tracks here like so the first one is going to uh so I can hold shift and click twice and the first one is going to go from zero and zero to oh I need to make sure I press enter on that zero and to the maximum length of the float track to a value of let's make it 150 so this is the distance in cenm that our camera will move forward I can click these two icons here to zoom and I'm not going to smooth this one out I want it to be quite Snappy so I'm just going to leave it like that so from 0 0 to 0.1 and 150 and let's set this one up this other one up in a moment I'll just back out to the event graph so we've got these two float tracks now you can see new track zero and new track one actually just to make this a little bit clearer let's rename this uh first float track to um emra offset like so and let's rename this other one to camera fov for field of view and now you can see we've got this camera offset track and this camera fov um what we can do is get our camera boom right here drag it out and we are going to set uh set camera offset set socket offset sorry set socket offset we can plug this into the update right here we can right click here and split the struct pin and if we look at our camera boom offset settings in The View Port here you see we changed this to 175 this one takes it uh out to the right and this one brings it up and this one here controls the direction that it moves forward so if I change this to 100 you'll see it moves forward if I change it to minus 50 you'll see it moves back so zero is the default and we want to make it 150 forward when we Zoom but we need to take note of these default values here 75 so that we can go into the event graph here and just make these 175 because these will not change and just plug the camera offset into the socket offset X like so so now when we right click our camera socket is just jumping forward by 150 units like so let's also reduce the field of view a little bit so we can check the default field of view by clicking on the camera here and looking right here field of view 90 um the lower this number the lower the field of view so the tighter the field of view will be so we're going to hold control and click and drag out the follow camera like so and we can set the field of view which is going to be set off of this float track right here the camera fov float track and because the default is 90 we want to set it from 90 to something a little bit lower so we can open up this timeline we can hold shift and click twice here and the first one I'm going to set to time 0 and value 90 and let's make the other one time 0.1 the maximum and 75 something like that now now when we right click the camera is coming forward and the field field of view is tightening up a little bit very nice good okay let's add some line Trace oh actually no we need to do the animation for the aiming we need to switch to the uh aim down the sights animation so let's do that really quick if we go into our animation blueprint I'm just going to close a few of these tabs so it's not too confusing go to the anim graph so we can close everything but the event graph and the anom graph just so it doesn't get confusing and all of these aiming animations are going to be played on the upper body right here so we can go into the upper body and go into the idle and what we can do is right click find a blend poses by bu again and this time this is going to be set off our aiming variable which we also need to pass over from our character blueprint so in the event graph we can add a pin here grab our character and get aiming promote this to a variable called aiming plug it in here copy the name right click here collapse nodes call it set aiming and now we have aiming we can grab it plug it into this blend poses by bull false will be the idle rifle hip and true will be the idle rifle iron sights right here make sure you select this one and check Loop animation let's back out to our upper body anims and go into our walk run here actually before we do that let's uh contrl C this blend poses by bull and then go into walk run we can paste this in and this one will go into our false pose and I'm going to use idle rifle iron sights again for the walking um so we don't actually need we don't actually need two states at all um what we can do is just delete the walk run um but I am just going to leave that there in case you want to make any changes uh you don't have to do it this way but I am just going to use the idle uh poses for the upper body because the other ones have just a little bit too much movement and your dude is slowing down when you aim anyway so it it doesn't look too bad at all I'll show you what it looks like right now so we've got that aiming and and if we're walking see his upper body is still going to move around quite a bit because of the legs bobbing up and down um but yeah so that's that's pretty good like that all right uh let's add a line Trace so how we're going to do that is with some very basic fully automatic firing logic so we're going to go back to our third person characters blueprint in the event graph and Below all this stuff I'm going to right click and find the left Mouse button and once again I'm going to create a variable I'm going to call it firing I'm going to drag this out and duplicate it set it as true off of pressed and false off of released and we are then going to create a branch you can do this by searching for branch or you can hold B and just click if you hold B on the keyboard and click you can create a branch and we're going to plug this firing Boolean into the branch right here and we're going to create a loop here so very basic Loop what we can actually do is put everything into a function so I'm going to create a function here I'm going to call it fire and within fire here we can put everything that we want to happen every time the gun fires so on the event graph here on true I can find my fire function so the gun's going to fire and then we are going to delay and I'm going to change this to 0.1 and then on completed here I'm going to loop back to this Branch right here so I can double click on these connections here to make some reroute nodes make it a bit neater and what's Happening Here is when we press the left Mouse button we set this variable to true and then because it's true this is going to loop it's going to play the fire function delay by 0. one of a second and then Loop and if it's still true it's going to keep doing this every 0.1 of a second if we release the left Mouse button and this becomes false it will break this Loop and if we just put nothing on here it will it will just break this Loop okay so inside of fire here we can set up what we want to happen every time we fire uh one of the things I want to happen is I want to play an animation on my weapon so I can grab my weapon from the components tab up here and just find play animation and the animation that I'm going to play is Fire w fire rifle W right here you want to make sure that this is the correct animation for the skeletal mesh that you've selected so if I just browse to this one here and open it up that is indeed an animation for this particular skeletal mesh that I'm using so very good um I also want to draw a line Trace here so that I can shoot stuff so what I can do is right click and find line Trace by Channel and I'm just going to draw this line Trace from the barrel of my weapon so if we find this Weapon by clicking on the weapon in the uh components tab right here and then browsing to the skeletal mesh asset you'll see I've got assault rifle B here and assault rifle B skeleton right here if I open up the skeleton what you'll find is here a muzzle flash socket and this is the socket that the muzzle flash particle effect will play from it will play at that location uh when I play that animation so what I can do is I can use this muzzle flash socket to draw a line Trace from and I'm actually just going to drag it out just about 1 cm like so um I can click on the muzzle flash socket right here single click click so that it goes to rename it and I can press contrl + C to copy that name and then back in my characters event graph off of the weapon right here I am going to get socket transform whoops get socket transform and then paste that socket name in right here muzzle flash I can right click here and split the struct pin the location can go straight into the start of this line trace and off of r rotation I'm going to get the forward Vector going to multiply this and I'm going to right click on this pin and change it to float single precision and I'm going to multiply this by however far I want this line Trace to go from this uh from the socket here the um the barrel of the weapon so I'm just going to change this to 15,000 for 150 M I can plug this into the end point here and change the draw debug type to for duration and hit compile and save here and now if I hit play just going to turn the volume down here so I don't destroy my eard drums uh and now we have very basic fully automatic firing logic with a line trace and last but not least let me show you how to apply damage to an enemy so what we're going to do is just use the third person character as an enemy I'm not going to show you how to set up any AI or anything like that I'm just going to show you how to use the line Trace to uh apply damage to an enemy so I'm just going to grab the BP third person character here and just put it out in the world like so and this is going to be our little test dummy the first thing I want to do um to to use this line Trace that I've just set up is create a new Trace channel so what I can do is go to edit and project settings and search for Trace Channel and you'll see here Trace channels we've got nothing here no custom Trace channels I can click new Trace Channel and let's just call it hit scan sorry I've forgotten how to type this morning and we'll leave the default response to block and hit accept and now we've got this new Trace Channel hit scan what we can do is close that now and we can change the trace channel here might have to uh refresh nodes and then hit scan will come up right here so we'll change the trace channel to hit scan and then we want to check the Collision settings on this character remember this is the character that we're we're shooting at as as well uh so the first thing I want to do is check that the capsule component ignores this hit scan Trace channel so we can select the capsule component and we can search for collision and if we drop down Collision presets right here you'll see that this is blocking everything except the visibility Trace channel so we can change the Collision presets here from porn to custom and then on hit scan I'm just going to to click ignore like so so this capsule component is going to ignore that line Trace that we're drawing from our weapon I can then with Collision still searched for I can select the mesh right here and we've got the Collision presets of the mesh right here I can drop this down and just make sure that it is blocking hit scan like so so just like that if I now shoot this enemy you'll see denoted by the little red squares that we are hitting this enemy but I can still shoot between his legs and over his shoulder and whatnot because it is not clipping with that capsule component and now uh what we want to do is go back to our event graph where we fire right here and I might I'm just going to put it with within this function right here the first thing we want to do on the line Trace channel is off the return value here we can hold B and click and find a branch and plug in the return value right here because if we don't hit anything we don't want to do anything right here but if we do hit anything we want to apply damage so we can drag off the out hit here and break hit result and this gives you a bunch of hit results of of what you've hit what we can do is drag off of hit actor right here and just find apply damage plug this in right here and let's just make the base damage 20 for now so now what this does is um it gives us the use of another node called event any damage or event received damage so this will apply damage to whatever actor it hits and if we just go back to our vent graph here and find event any damage this will be activated anytime that apply damage is activated and that could come from a number of different sources but um what we might do is create a very quick Health variable and health and damage system very rudimentary just so that we can tell that this is working so I'm going to create a new variable I'm going to call it health change this to float and I'm going to compile so that I can set a default value of this health variable once you compile you can set the default value and we'll set it to 100 so it will be 100 as default and anytime we um get damage here we're going to take off of that health so we're going to set the health as the health minus the damage just like so and we're only going to do this if the health is greater than zero so I'm just going to add a reroute node here and get this a little bit out of the way and I'm also going to grab the health and check if it's greater whoops greater than zero put this on as the condition for a branch sorry this is a little bit cluttered here so if the health is greater than zero then we can do some damage um and every time that we take off the health we want to check that um if the health is zero or less so we can also grab the health and check if it's less or equal so less equal than zero make a branch plug this in and if the health is less or equal to zero let's just make our guy ragd doll so how we want to do that is grab the mesh here and what we can do is set simulate physics and check simulate we can set physics uh blend weight set physics blend weight and we want to set the blend weight to one this is like an alpha it goes from 0 to one and we can also uh set Collision enabled as query and physics physics where is it Collision enabled query and physics like so and this will just make him rag doll so now if we hit this guy five times he will rag doll like so and if you just want to see this um Health in action what we can do on the event any damage here is just add a print string right to the start of this logic and we will just print the health so plug the health into the inst string right here and let's just make this yellow so every time we hit him it will print his health and up the top left you can see 100 80 I keep missing 60 40 20 and he's died on 20 which is a bit odd um what's happening there ah the only reason uh it will be showing that is because the print string is before the set health so it's showing you what the health was if that makes any sense so I am just going to place the print string after the set Health right here and plug this in right here and that should now be working correctly I mean it was working correctly but it was also showing 100 when we first hit should be saying 80 60 40 20 and zero and he's dead nice all righty guys once again if you haven't already please hit like And subscribe and if you're interested in a bit more of an intensive tutorial on third person shooters I do have a tutorial showing you how to set up a multiplayer third person shooter so if you'd like to get onto that one I'll leave a card up in the top right of the screen uh thanks very much for watching and I will see you on the next one
Info
Channel: MizzoFrizzo
Views: 9,612
Rating: undefined out of 5
Keywords: ue5, tutorial, animation, video game development, blueprint, unreal engine 5, tute, true first person, shooter, shooting game, realistic, unreal engine 5.2 first person shooter tutorial, how to make a fps game, fps tutorial, TFPS, ue5 weapon system, unreal engine tutorial, unreal engine 5 weapon system, unreal engine gun system, unreal engine 5 fps tutorial, ue5 fps tutorial, unreal engine fps tutorial, ue5 fps, ue5 first person shooter, how to add a gun, pick up weapon
Id: -IM5IE_XiLI
Channel Id: undefined
Length: 57min 3sec (3423 seconds)
Published: Wed May 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.