Looking for help to finish my simple Recoil system for my FPS project

Hello,

Its been days since I am trying to have a polished recoil system for my FPS. And I just can’t figure how to finish it, the FInterp To node is so weird to me so I am asking for help here.

What I want is this :

The more the player is firing an automatic weapon, the more the bullet are spreading around the cursor, with a max value that is exposed.

A vertical pitch input each time a bullet is fired.

So the bullet spread is working fine, but I cant find any way to increase smoothly the pitch of the player. I first simply added a Pitch input on the player controller. It worked but it was “snapping” the new pitch value, so I started looking how to smooth it.

I discovered the FInterp To node wich seem to do what I want. So I created 2 variable in my weapon BP. “Current Pitch” float, wich I set everytime a bullet is fired by getting player controller and break rotator on Get Control rotation. After this, I increase a new variable “Target Pitch” by a float “Recoil Force” that I set at 1 for example.

And then, in the Event Tick, i call a function update Pitch with the finterp to return value. The FInterp To node is taking the Current Pitch as the “current” entry, “Target Pitch” as the Target entry, and Interp Speed that is exposed.

All of this is in my Weapon_BP parent class.

The result of this actually is when I fire with an automatic weapon ( semi not supported for now but I don"t mind I can fix it later ), the camera goes right to the ground instantly. If I shoot again it goes to the sky, like 180 degrees oposite. Sometimes it goes random. Its a bit hard to describe it because it seems so random.

I will send some screenshots of the function. I am also willing to go vocal discord if you prefer and if you have time.

thanks a lot !


That fire event of yours gets triggered when you hold down the key to fire, right? I think that random looking outcome you see is the result of your float type variable named “current pitch” being updated constantly. Try storing it’s value at the start of the event and only re-enabling it to be assigned to a new value once the player’s rotation around y axis reaches the target value or releases the fire button.

How many bullets can you fire per second? From your BP, you said you’re adding 1 degree to the target pitch on every shot. So after 90 bullets, you’re gonna be staring at the floor. After 270 bullets, you’re gonna be staring at the sky.

If you want recoil, I think you’d want the pitch to come back up. But if you’re firing a LOT of bullets, that’s gonna be difficult to do in a way that isn’t jerky. You’d probably want to reverse the FInterpTo once the TargetPitch has been reached (at a slower speed). And then use the original FInterpTo after every bullet. Then you can tweak the speeds.

Regardless, I think you should have a limit on the Target Pitch. And you should try using an angle offset. Either as a variable that you manually track or that you set on a separate component like the camera boom.