How can I implement Recoil Pattern into my gun?

Currently I’m working on a gun but instead of the recoil just being the barrel puts force up into the sky by using SpringRecoil, I want to make it have a recoil pattern so people could learn it but I can’t find a relevant or recent topic helping.
Here is currently the code for my current recoil I already mentioned that uses SpringRecoil
You could just make a new function if you want, doesnt have to be similiar to this, I just want to have a modular recoil pattern that works
Thanks! :smiley:

function module.Update(Viewmodel, deltaTime, RecoilSpring, BobbleSpring, SwayingSpring)
	Viewmodel.PrimaryPart.CFrame = workspace.Camera.CFrame
	
	local Bobble = Vector3.new(GetBobbing(10), GetBobbing(5), GetBobbing(5))
	local MouseDelta = game:GetService("UserInputService"):GetMouseDelta()
	
	local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	
	BobbleSpring:shove(Bobble / 10 * (Character:WaitForChild("HumanoidRootPart").Velocity.Magnitude) / 10)
	SwayingSpring:shove(Vector3.new(-MouseDelta.X / 500, MouseDelta.Y / 200, 0))
	
	local UpdatedRecoilSpring = RecoilSpring:update(deltaTime)
	local UpdatedBobbleSpring = BobbleSpring:update(deltaTime)
	local UpdatedSwayingSpring = SwayingSpring:update(deltaTime)
	
	if AimDownedSight then
		Viewmodel.PrimaryPart.CFrame = Viewmodel.PrimaryPart.CFrame:ToWorldSpace(CFrame.new(UpdatedBobbleSpring.Y/4, UpdatedBobbleSpring.X/4, 0))
	else
		Viewmodel.PrimaryPart.CFrame = Viewmodel.PrimaryPart.CFrame:ToWorldSpace(CFrame.new(UpdatedBobbleSpring.Y/1.5, UpdatedBobbleSpring.X/1.5, 0))
	end
	Viewmodel.PrimaryPart.CFrame *= CFrame.new(UpdatedSwayingSpring.X, UpdatedSwayingSpring.Y, 0)
	
	Viewmodel.PrimaryPart.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X) * 2, 0, 0)
	game.Workspace.Camera.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X), math.rad(UpdatedRecoilSpring.Y), math.rad(UpdatedRecoilSpring.Z))
	Viewmodel.Items.M4A1.Sight.CFrame = Viewmodel.Items.M4A1.Sight.CFrame:Lerp(Viewmodel.PrimaryPart.CFrame, game.ReplicatedStorage.Values.AimAlpha.Value)
end
1 Like