Gun Recoil

I have a gun that shoots projectiles out of it’s muzzle, and using a line trace from the center of the camera forward, the projectiles will rotate and always hit whatever the trace hits.

Now I want to add recoil. I don’t want patterns(like in CSGO), I just simply want a bit of randomness. I want to be able to control this randomness because I have multiple guns which should have diffrent recoils.

I made two float variables (Vertical and Horizontal Recoil) and now I’m stuck on how to add these to the location vector at the end of the line trace.

Any ideas?

Hey @,

It might work better to add the recoil value before the trace, not after. You can break the forward vector and add three Random Float in Range nodes to add values to the Z axis for vertical recoil to the X and Y axis for horizontal recoil. Then hook this back up to your vector X float to give it some distance.

The numbers for recoil would have to be tweaked to your liking. You can create a variable that feeds into the min and max values for each float range and use that to set recoil on all your guns.

I hope this solution works for you!

So it’s the break and make vector nodes that do the magic here. I did not knew about them. Thanks a lot!

you can also right click the vector pins and break them directly on the node itself. This is also true for any variables which are aggregate of several variables, like structs, rotators, etc.

Same thing as break/make nodes, just different way to visualize.

Hi! I am brand new to UE5 and have been in the process of making my first game, and i am looking to have custom recoil. I have yet to find any sort of tutorial for making the recoil through blueprints, and I was wondering if you could possibly point me in the right direction?