top of page
Search

Dev Log#19: Making HitScan Weapons

Hit scans weapon in my game include a pistol, smg, sniper and a shotgun.

Pistol smg and sniper are all derived from a hit scan weapon class and the shotgun is derived from its own class because the functionality is unique since it has a pellet spread. The sniper required its own widget blueprint for the sniper scope.


What the hit scan weapon class is doing? So its performing a single line trace in a function called weapon hit trace. Taking the start point adding the distance to the hit target and multiplying that by 1.25 to just extend the trace just past the target.

If a hit scan weapon needs to have bullet scatter it can do so through the use of boolean. This will use the trace with scatter function which will utilise a sphere radius that is used as the point where the scatter will trigger. The actual trace will extend past this sphere but the bullets will be less likely to hit your opponent.


Shotgun Class:

The unique shoot functionality for the shotgun creates a TMap to contain the number of hits. I'm then using a for loop the shotgun pellets so each pellet is conducting a line trace. A hit is recorded getting a pointer of the character that was hit and storing it in the TMap with a value of 1 per hit.

Damage is then applied after this for loop is conducted and it is multiplied by the value of the Key pair.

So for example if player 1 gets hit by 4 of the shotgun pellets, a pointer referencing player 1 will be stored in a TMap as a Key and be given a value of 4 representing the 4 hits. Then damage is applied to player 1 by multiplying the value of damage by 4.


The sniper was given its own widget blueprint because the HUD just needs to be the sniper scope whenever a player is aimed in with it. I'm doing the code to create this and ensuring this inside the character's blueprint which is nothing too crazy.

 
 
 

Comments


bottom of page