How to I tween the camera recoil effect relatively?

Okay so I have this gun system, it uses a shotgun. And I’m trying to implement a recoil effect for the Camera, because it won’t feel realistic with just the recoil animation on the gun only, almost every FPS game implements it obviously.

So the recoil seems to be working:

However it only looks fine if I stay while shooting. When I move or move my camera around and shoot it, the recoil effect becomes like this:

So it’s like, my character and the ViewModel weapon goes first then the camera goes second. Or perhaps, vice-versa.

So what I think is, tweening the X axis only while the remaining Axis like Y Z stay relative.
Like tweening it relatively?

Here’s the code that does the recoil effect on the Camera:

camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(10),0,0)
TweenService:Create(
	camera,
	recoilTween,
	{CFrame = camera.CFrame * CFrame.Angles(-math.rad(10),0,0)}
):Play()

Basically I use Tween instead of for loop because the code would have to wait for that for loop to finish before moving to the next line and so on and so forth.

Any ideas on how can I fix this glitch? Perhaps how would I tween the recoil effect relatively? Just reply below if you have suggestions and other stuff.

2 Likes

That’s because the tween uses the old CFrame value from where you were standing when it was called.
You’d have to maybe lerp the CFrames manually but I have no idea how that works so I can’t really help you there.

1 Like

Try something like this. I think the problem is that since theres no type of wait between the Tweens you need one to be not choppy.

local tweenRecoil = TweenService:Create(
	camera,
	recoilTween,
	{CFrame = camera.CFrame * CFrame.Angles(-math.rad(10),0,0)}
)
tweenRecoil:Play()
tweenRecoil.Completed:Wait()

That’ll interrupt a part of the script where the crosshair animates when I shoot. The issue is When I move while shooting, my model like goes first then camera goes second and goes back to normal. Also the recoil effect should be played whenever I shoot. If I hold the Left Click, the recoil should keep playing until I let go.

There is simply no way to do a “relative tween”, and TweenService is unfortunately made to give us very little control over how things work. One solution in this specific case is to use Humanoid | Roblox Creator Documentation

1 Like

Then you can use Courtine.Wrap() a function so it doesn’t “interrupt” anything.

2 Likes

@ThanksRoBama But CameraOffset doesn’t support Rotation as it is a Vector3. Vector3 doesn’t support rotation. The recoil effect I’m trying to achieve is making the player face slightly up when shooting.

Suggestion
For my framework I actually dont have a tween I have a Camera CFrame Lerp instead so that tween times dont override and regardless how much recoil is being put it it still looks stable and not super crazeballs. I have this on a RenderStepped function which gives the visual effect of recoil very smoothly

RecoilOffset = RecoilOffset:Lerp(CFrame.new(0,0,0) * CFrame.Angles(RecoilValue,0,0), 0.2)

RecoilValue is completely customizable to a very small value and can give you pretty decent results. I have RecoilValue reset to 0 once the recoil is applied to avoid the camera drifting off in the Y direction. Once youre done inserting that you can simply put this down here

CurrentCamera.CFrame = CurrentCamera.CFrame * RecoilOffset

Its all basic it mainly depends on how you implement it. :stuck_out_tongue:

6 Likes