Use enhanced input action to fire single and full auto weapons

Hi,

with the enhanced input I’m not sure on how to have the one input node fire different types of shooting. I want to be able to fire semi auto guns by clicking RMB and hold RMB to fire full auto. I can do this with 2 different mappings but is it possible to do with just one? The FireBullet function just spawns a projectile from the barrel

fire event on the player character

gun parent
image

single fire gun

full auto gun

Expand the EhnhancedInput event, you should see a float value that shows for how long that key has been pressed, you can use it to trigger semi or auto fire.

I found quite old prototype for shooting weapons, however for some reason it is not working (either lost in translation from 4.12 to 5.2, or it is backup of unfinished system).

I am migrating all those ancient prototypes to 5.2, but it may take time.

At some point i made it all with FSM plugin from marketplace. I think finite state machines are best for this problem, but that requires C++ and custom build state machine, and would be best solution for projects with some AAA quality/funding.

I describe what i remember from my prototype (And will try to find working one):

  • i made enumerators for “Stage of shooting cycle”: idle, first shoot, auto shooting, last shoot, reloading
  • then another for type of firing: single shoot, autofire, continous (this one was for weapons like flamethrower)

weapon system is split into modules/parts:

  • parent weapon class is weapon with all shooting logic, but not visuals. It receives events like “start shooting” “stop shooting” directly from player controller ie. shoot pressed, shot released.
  • then there is shoot cycle/logic that generates events for “spawn projectile” (and this is exactly what i cannot find in working state). It uses enumerators for stage of shooting , and type of shooting.
  • weapon only spawns projectile actor, does not bother how muzzle looks, if projectile is line trace, or rocket, or bullet

Then i have projectile system which is again:

  • parent class projectile that has all logic
  • child class that has mesh emitters and all visuals

I don’t quite understand cause they fire off the same node so how doI split that logic?

Input Action

Event

Example:

This way I would have to create seperate functions for single and auto fire modes tho right?

You can recycle the same one, it was just to show when the input is different, you don’t even need to check the elapsed seconds if you want to call the same function (it’s important that you set both pressed and hold in the input action)

1 Like