Line Trace Shooting Mechanics – Part 2: Line Trace and Localized Damages

Read the first part of this tutorial here.

 

Second Part – Shooting Mechanic Function


Depending whether you have a 3rd Person Shooter like my project or if you’re handling everything in First Person, your method to do the Line Trace in Blueprints will be slightly different. In my case as a TPS I have to cast the Line from my character’s weapon towards an infinite point from my camera.

Shooting Mechanics Tutorial Part 2 - Line Trace and Damages

 

Once the Blueprint got a confirmation that the Line Trace was successful and hit something, we can spawn a small FX and it will provide valuable debug infos on the hit location. And everyone loves explosions.

Then what I’m doing is to check if the hit landed on a character or just somewhere in the environment. It can be done with a Multi-Trace but I chose to do it with a branch and a class-check. Simple but effective. If you have different blueprints for other “creatures” though, like Zombies or Dinosaurs, a Multi-Trace might be needed to handle the hit differently.

Once it hits the node “Damage Localization”, we pass in the third part of our blueprint.

 

 

Third Part – Localized Damages


 

Beforehand, I stored my characters’ bones names inside 3 arrays corresponding to Double Damage (Head, Neck…), Half Damage (Hands, Feets…) or Normal Damage (Chest, Back…) and I check where the hit bone belong. The trick is, I don’t want to store all the bones of my character in my arrays, it would be too time-consuming to add every single joints manually. So I just added the main ones. If the bone hit isn’t found anywhere in those 3 arrays I recursively check their parents until a major bone is found and will use this one as a damage handler. I added a failsafe at the bottom of this blueprint that will only check recursively 4 times and give up, just in case something went wrong. The worst case scenario is if I hit the tip of my character’s fingers. It will have to check their parents thrice before getting a registered bone.

 

Shooting Mechanics Tutorial Part 2 - Damage Localization.

Bone Hit = Right Hand’s Middle Finger. Exist in Double Damage Array ? No. Half Damage ? No… Normal Damage ? No.

So Get the parented bone: Right Hand. Does it exist in Double Damage Array? etc etc.

Shooting Mechanics Tutorial Part 2 - Bones Array
The 3 arrays containing the 14 major bones.

 

Shooting Mechanics Tutorial Part 2 - Localized Damages
My characters bones. As you see most of them aren’t in my arrays, but their immediate parents are. You can see some sockets that I use for my equipment system. *teasing*

 

 

That’s it for my Shooting Mechanics. Feel free to leave a comment if you have any related question, I’ll be glad to answer all of them!