How could I make my recoil smoother?

I wrote this recoil script a while back, and I’m not entirely satisfied on how it turned out, so I decided to redo it. The only problem is, I have no idea why this isn’t a smooth lerp.

Here’s the code:

function RecoilShove()
	local Recoil = 0.17
	
	local recoilUpdate = CFrame.Angles(Recoil,0,0)
	local recoilUpdateDown = CFrame.Angles(-Recoil,0,0)
	
	Camera.CoordinateFrame = Camera.CoordinateFrame:Lerp(camera.CFrame * recoilUpdate, 0.1) 
	spawn(function()
		wait(.15)
		Camera.CoordinateFrame = Camera.CoordinateFrame:Lerp(camera.CFrame * recoilUpdateDown, 0.1) 
	end)
end

Any help would be great!

Youtube demonstration: https://www.youtube.com/watch?v=JdQoodkD0qk

1 Like

Sorry to be that person but this is in the wrong category. This is supposed to be in #help-and-feedback:code-review. Thanks.

1 Like

Oh okay, but should I repost? Or would my repost just get taken down?

1 Like

Oh wait sorry I didn’t notice it is in the right category. Sorry.

1 Like

Okay, cool.

(30 charactersssssssssssss)

1 Like

Is there anyway we can see a video of this please?

Uhm, lemme see.

bhebedhgedgefgysegfawdawdawdawdawd

1 Like

Done. You can find it at the bottom of the post

1 Like

You are not using :Lerp correctly in this case.

The :Lerp() method creates in-between points between a start, and end point. But Keep itself does not smoothen things, but just generate the points to help you do so.
Here is an article on Bezier Curves, that has some demonstrations that might help you understand Linear Interpolation:
https://developer.roblox.com/en-us/articles/Bezier-curves

To see examples of how you can use some math to create realistic recoil, just search for “recoil” here on the forums.

Another option if you are not in the mathy mood, is to use is TweenService. TweenService is great because it does the work for you, and offers a plethora of EasingStyle’s to change how the Tween flows.

Hope this helps!

1 Like

Thanks for the reply! I have tried tweenservice, but got lazy and ditched it because I felt like lerping was way easier. Anyways, I feel like the number all the way to the right (0.1 in this case) is the delay?

It seems to work this way when I do other things, just not in this case.

Not quite. The first parameter is for inserting the final destination point(where you want to end up).

The second parameter, is what percentage of the distance of that point you want :Lerp() to return.

Here is a video that explains how Lerp works:

1 Like

Hmm, in this script it seems to be that the other side is delay or something?!?!?!?

Here’s the script that I’m talking about:

runServ.RenderStepped:Connect(function()
	--viewer:SetPrimaryPartCFrame(viewer:GetPrimaryPartCFrame():Lerp(camera.CFrame * Main, 0.4))
	if PrimaryEquipped == true then
		viewer:SetPrimaryPartCFrame(viewer:GetPrimaryPartCFrame():Lerp(camera.CFrame * Main, 0.4))
		
		if aiming == true and PrimaryEquipped == true then
			Main = Main:Lerp(CFrameData.ads, 0.1)
			viewer:SetPrimaryPartCFrame(viewer:GetPrimaryPartCFrame():Lerp(camera.CFrame * Main, 0.85))
		elseif PrimaryEquipped == true then
			Main = Main:Lerp(CFrameData.main,.4)
		end
	end
end)

Every time I change the number that you say is the point you want the lerp to run, it just changes how fast my viewmodel gets from point a to point b.

I have no clue why that is

I don’t believe that is how it works. It should shift the CFrame instantaneously regardless of the second parameter. You are literally just teleporting the CFrame of an object, to the value Lerp returns. Watch the tutorial video I sent to understand how it works.