Creating Assault Rifle

riflescreen1

BasicWeapon blueprint now supports a lot but it isn’t supporting automatic fire like assault rifles have. It will be really simple to implement now.

  • Rifle should use automatic fire,
  • We will use existing functionalities to drive this weapon,

Basically I will implement almost all of the weapons from Military Silver Pack and then move forward with gameplay. I want to have BasicWeapon functionalities fully implemented and tested out.

For those who haven’t read earlier posts you should implement BasicWeapon blueprint to get this working. So check out earlier posts!

Stop Fire functionality

Add one new dispatcher to GameplayCharacter: OnWeaponStopFireWeapon (inputs WeaponType)

Now in BP_BaseWeapon

Add one new variable:

  • RiflesFireRate (float, default 0.1)

And one new function:

  • StopFire, – leave it blank,

Go back to GameplayCharacter and add new custom event: StopFire.

stopfireinput

So now we are driving input (only PC for now)

Creating Weapon

Go to BP_Weapon_AssaultRifle (we had created it earlier) and fill variables:

  • CurrentAmmoInMag: 30,
  • MaxAmmoInMag: 30,
  • CurrentAmmoInBackpack: 100,
  • MaxAmmoInBackpack: 100,
  • SpreadMin: 0.02,
  • SpreadMax: 0.2,
  • SpreadCurrent: 0.1,
  • SpreadDecreaseSpeed: 0.25,
  • MinWeaponDamageModifier: 0.7,
  • MaxWeaponDamageModifier: 1.2,
  • CritDamageModifier: 3,

Add one new variable:

  • IsRifleFiring (bool),

Now in event graph:

riflebp_graph

And that’s whole rifle functionality 🙂 We are using timer to make automatic fire. It’s really easy.

Creating Animation

In HeroFPP_AnimationBlueprint. If you were reading earlier posts you should be able to do this by yourself. It’s the same thing:

  • Position hands to fit the weapon,
  • Use RifleRecoil bool to drive the recoil bone modify alpha,

So, create two new variables like in earlier post:

  • RifleRecoil (bool),
  • RifleRecoilAlpha (float)

Now in event Initialize Animation we need to know when we are firing and when firing ends.

animbpbeginplay

And in Update Animation let’s drive RifleRecoilAlpha

animbpriflerecoil

Anim graph should take RifleRecoilAlpha and modify bone.

riflerecoil

Final result:

8 thoughts on “Creating Assault Rifle

    • yes true, + i needed to repair “get owner” to “get player character” before dispatcher and its working properly…

  1. Hi Kendrick, yes you are correct, sorry for the late reply – Should be OnCharacterStopFireWeapon.

    Follow up question – I have everything working, but is there a way to adjust the blending for the recoil? What I’d want is a super short, sharp, repetitive recoil that happens with each shot. But right now, the gun (I’m using my own) recoils back and basically stays in place until I let go of the mouse. I see it pop forward a little now and then while shooting so recoil functionality is definitely working, just seems like too soft a blend in and out.

  2. Nvm – figured it out. To try it out you can follow the tutorial as written, but with name368’s “get player character” fix for 4.10. Then either remove the Delay node in the Anim Blueprint branch where you’re handling Rifle Recoil (the section with the FInterpTo Nodes), or set it to a delay duration of 0. I also changed the FinterpTo values to a higher Interp speed (25).

  3. Hello!
    Anyone knows why i can’t reload my rifle, i have given the datas correct in my backpack, but he don’t reload any ammu?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.