I’m trying to make a recoilpattern for my gun but it isn’t that great. I wanna make the camera shift to the new camera angle, not it teleporting to it, should I use tweening?
local Camera = workspace:WaitForChild("Camera")
local RecoilPattern = {
{3, 12, -1, .8, -0.1},
{6, 12, -1, .8, 0.1},
{8, 12, -1, .8, -0.1},
{10, 12, -1, .8, 0.1},
}
local RecoilReset = .5
local curshot = 0
local lastclick = tick()
local Player = game:GetService("Players").LocalPlayer
function lerp(a,b,t)
return a * (1 - t) + (b * t)
end
local function GetBobbing(addition)
return math.sin(tick() * addition * 1.3) * .5
end
function module.Update(Viewmodel)
Viewmodel.PrimaryPart.CFrame = workspace.Camera.CFrame
end
function module.Cast(origin, Endposition, Velocity, Damage, Viewmodel)
curshot = (tick() - lastclick > RecoilReset and 1 or curshot + 1)
lastclick = tick()
for i, v in pairs(RecoilPattern) do
if curshot <= v[1] then
spawn(function()
local num = 0
while math.abs(num - v[2]) > 0.01 do
num = lerp(num, v[2], v[4])
local rec = num / 10
Camera.CFrame *= CFrame.Angles(math.rad(rec), math.rad(rec * v[5]), 0)
end
while math.abs(num - v[3]) > 0.01 do
num = lerp(num, v[3], v[4])
local rec = num / 10
Camera.CFrame *= CFrame.Angles(math.rad(rec), math.rad(rec * v[5]), 0)
end
end)
break
end
end
end
some of you probably have seen something similiar to this made by someone else
also dont ask why the m4 is facing sideways