Line Trace Shooting Mechanics – Part 1: Input, Ammos and Autofire

For our shooting mechanics I used a “simple” Line Trace that got complicated… quite fast. What I needed:

 

  • All weapons uses Ammos
  • Some weapons have Auto-Fire
  • Different Magazine Sizes
  • Localized Damages
  • Different results between a Pawn and random environment

 

Quite a lot to detail as you can imagine. I divided this post in two parts: First Part will talk about Handling Inputs, Ammos and Auto-Fire. The second part will talk about Line Trace and Localized Damages.

 

First Part – Handling Input and Entering the Auto-Fire Loop


Once we got the Shooting Input Event, we need to figure out several conditions before actually entering the Auto-Fire Loop. Things like HasWeaponEquiped and HasAutoFire needs to be sorted out first.

 

Shooting Mechanics Tutorial Part 1

Then, we can enter the proper AutoFire Loop, which looks like this:

Shooting Mechanics Tutorial - AutoFire Loop

 

We extract the Rate of Fire from our weapon, and this will input the delay between each shot. Delays are not the best option performance-wise, but in blueprint it still make things quite easier.

 

 

The next thing to do is to calculate if the player still has enough ammos in his weapon, else he won’t be able to shoot. If all my requirements are met, we can finally start the shooting process. Removing a bullet from the magazine, updating our HUD, and triggering the massive Shooting Mechanics Function…

Read the second part of this tutorial here.