i’m trying to achieve smooth and good looking recoil / kickback for an fps engine im working on. by recoil i mean when you shoot, the gun moves. right now i have it lerp backwards but i just dont think it looks good enough. im trying to acheive something more or less like this where it moves while its shooting https://www.youtube.com/watch?v=4jD1G8RCKv0&ab_channel=DarkAngel

this recoil also makes the gun rotate a bit too and i was wondering what kinds of math i would need to do to get a result thats somewhat similar

3 Likes

```
local RecoilPattern = {
{3, 12, -1, 0.77, -0.1},
{6, 12, -1, 0.77, 0.1},
{8, 12, -1, 0.77, -0.1},
{10, 12, -1, 0.77, 0.1},
}
local RecoilReset = 0.5 -- Time it takes for recoil pattern to reset back to 1
local curshot = 0
local lastclick = tick()
function lerp(a, b, t) -- Gets a number between two points using an alpha
return a * (1 - t) + (b * t)
end
function ShootRecoil()
curshots = (tick() - lastclick > RecoilReset and 1 or curshots + 1) -- Either reset or or increase the current shot we're at
lastclick = tick()
for i, v in pairs(RecoilPattern) do
if curshots <= v[1] then -- Found the current recoil we're at
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 = Camera.CFrame * CFrame.Angles(math.rad(rec), math.rad(rec * v[5]), 0)
Run.RenderStepped:Wait()
end
while math.abs(num - v[3]) > 0.01 do
num = lerp(num, v[3], v[4])
local rec = num / 10
Camera.CFrame = Camera.CFrame * CFrame.Angles(math.rad(rec), math.rad(rec * v[5]), 0)
Run.RenderStepped:Wait()
end
end)
break
end
end
end
```

try this one, it isn’t mine by the way

1 Like

im sorry, i should of clarified i was talking about recoil as in when you shoot, the gun moves, which i have confused with kickback. the script is great but it’s not what im looking for. im looking for something more like this https://youtu.be/bL5-yJd-SLc?t=25 when the gun moves left and right a bit when shooting

You can just animate that then use math.random to select which to play randomly. Of course, this should be used to some extent, but since this may not look like what you want, or it may distribute a bit of uniformness, you can just do it procedurally through a script instead of animating it altogether, given that the offset of your gun is set using a Motor6D.