Doing differing damage based on where they are hit is not difficult at all, for raycasts anyway. You have to create a physical material for each body part that can be hit, e.g. head, torso, left arm, left hand, etc. and then set everything up in the PHaT. Also, in the physical material, you can set the Destructible Damage Threshold Scale to numbers between 0 and 1, like 1 for head, .25 for torso, .1 for arm. The hit result of a raycast can return that information, which then can be multiplied by weapon damage to get the amount of damage to be done to the character, which can be then passed on to another function.
At first I did the interface route. But that was before I worked on networking. When I started networking, I found it much easier to do the Apply Damage / Event Any Damage combination and also thought about the security of health and damage, which I feel should rely on the server instead of the client.
The main gist of how I do the firing / damage is this:
- Client calls function that calculates firing vector
- Client sends vector to server (might move calculate firing vector to server as long as performance doesn’t take a hit and instead just send the actor who did the firing and let the server calculate the vector)
- Server calls a Fire event which executes on all clients. This event calls Fire on weapon blueprint so sound, impact, particle effects can be seen/heard across all clients.
- If the client can fire (has bullets left) proceed to raycast. This is so when the client doesn’t have bullets, still call the Fire on weapon blueprint for everyone to hear the empty trigger pulls, but there is no raycast.
- (Server) Use firing vector to perform raycast.
- (Server) From the Hit Result, calculate damage (hit result has the phys mat, which the destructible damage threshold scale can be pulled from and used to calculate total damage) and apply damage to the hit actor (also from hit result).
- Event Any Damage will subtract health based on the incoming damage and will set an boolean if health goes below zero.
The rest is a bit hazy as I’m not looking at the code right now. But what happens is if the damage is lethal, the client will go into ragdoll (executes on all so everyone can see the other player’s death) and will no longer have pawn collision nor input.
If this is confusing, I’ll try and get some screenshots of all of the function calls. It’s a bit messy so I’ll have to clean up the lines.
If you want more information on projectiles and their damage, I suggest looking at that multiplayer cowboy shootout directly from Epic. That’s partially where I learned to do the server damage stuff.