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.
1 2 |
<strong>This Tutorial has been created using Unreal Engine 4.8.2</strong>. Make sure you are working on the same version of the engine. |
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.
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:
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.
And in Update Animation let’s drive RifleRecoilAlpha
Anim graph should take RifleRecoilAlpha and modify bone.
Final result:
Hello,
I maybe found a “bug” when you shoot more than your 30 bullet, it continue to fire.
You just need to add a branch like that : http://prntscr.com/80r2xh in the BP_Weapon_Rifle Event Graph
yes true, + i needed to repair “get owner” to “get player character” before dispatcher and its working properly…
Is OnWeaponStopFireWeapon actually
OnCharacterStopFireWeapon ? Is it a typing error ?
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.
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).
this does not work in 4.13.0 the weapon will not stop fire when mouse button is released
is there a work around?
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?
Ok, figured out by my self, i had guess the parent note to connect from the reload
function.