Advanced Combat System Tutorial - Line Trace/Dealing Damage [UE4]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to another part of my advanced combat system tutorial series in this episode i will be showing you how to create a line tracing and how to damage the enemy so let's get started first locate your weapon and we will create a socket called start and another socket called end now position them at the start and at the end of the weapon close it go to the combat system component and create a custom event called trigger multi-line trace now we'll set dimer by event and return value will be promoted to a variable called multi-line trace timer now set these values to timer by event function and we will create another custom event called apply multi-line trace create a variable called character to hit class this will be the master combat character but it will be a class and it will be editable and exposing spawn now create another variable this will be called target hit and it will be of the type actor now let's set sequence and from the first one we want to multisph multisphere trace by channel then we want to get attacking weapon from that we want to get the weapon mesh and now get socket location copied here and set the names to start and end that we created for the weapon now set them in the trace and set the radius to 10. now the actors to ignore we want to make array uh let's add two pins here first we want to get owner and then we want to get the left hand and right head weapon now we want to check if we hit something and if we hit we want to set for each loop then we want to break the hit result from hit hector we get the class and we check if that is a child of the character to hit class then get the target hit array and check if it contains already the redactor afterwards get target hit again and let's add to it if it doesn't contain the actor now let's also pin this here create a custom event called stop multi-line trace get the trace timer and clear and invalidate timer by handle then get target hits and clear the array now in the sequence we want to get the retrievable delay let's just leave it at 0.2 and then we want to check if is attacking is not true and if it is not true we will stop multi-line trace now this last thing is just for the purposes if something goes wrong uh you will mainly stop multi-line trace by yourself in the functions but if something happens then this will stop it 100 so you don't have to worry about it now go to your animations and we want to create two anim notifies one will be when the attack is starting you can also create another track right here and create a new notifier called trigger multi-line trace and then at the end of the attack we want to create another notify called stop multiline trace and will this for all of the attacks now go back to your player nmbp get the notifies right there and we want to get the combat system um we actually can make this function so let's collapse into a function go into the function so the return node and a combat system component will be the output also this function will be pure now go back and we can just replace this rear now from the combat system component we want to get trigger multi-line trace and stop multi-line trace set them to the notifies and now when we play an equivalent weapon you can see the line trace is working but we don't have anything to hit so we need to create enemy character for this so create a child of master combat character this will be called mastery enemy i'm gonna create a folder for him open it up and let's set the mesh right here the rotation also and when it's done uh go to the capsule component and set the collision presets to custom we want we want to set visibility to block and camera to ignore i'm gonna rotate him right here and also i'm gonna go to the third person character and set the character to hit class to the master combat character you can set it to whatever you want and lastly after the trace i just want to see if we hit so i'm gonna print string right here now as you can see we can hit the target but we don't build any damage so for this we want to create an interface called damage interface it will have function called deal damage with one input of the type integer called damage then we need to set the interface in the third person character and the master enemy under the class settings after we've done that we can set the master enemy to have 100 health and then we want to get the event deal damage that's from the interface afterwards get combat system component get current health and we want to subtract the damage then we need to set current health afterwards we want to check if the health is less or equal to zero and if it is we want to destroy the actor essentially this is like a death afterwards i want to print string that will say how much hp he's got left now we need to go to the combat system component create a function called deal damage to target then cast to third person character and also create the input of the type actor you can call in target then if the cast is failed we want to cast to the master enemy and then deal damage the damage will be from the attacking weapon so get the attacking weapon get its weapon data break it and get the damage now we can just return now copy this part and just paste it for the third person character so it can deal damage also to him now go back to the line trace and set deal damage to target at the end of the apply function and also set the target from the hit actor now when we equip the weapon you can see he's got 50 hp left and when we hit again he's gonna die because our weapon deals 50 damage now if you also do not want to see the debug lines you can just delete them here and now you can see it's working as intended so thanks for watching i hope this video helped you somehow and i hope to see you in the next one bye [Music] you
Info
Channel: Darklore Creations
Views: 4,288
Rating: undefined out of 5
Keywords:
Id: Qjul1dAKChs
Channel Id: undefined
Length: 10min 6sec (606 seconds)
Published: Fri Aug 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.