So I’m trying to make an FPS game but I’m having a hard time trying to make the recoil, I want to try make the code that I put in move like a Tween (Like making the Camera glide upwards instead of making it teleport upwards) But I don’t know how to do that
local runService = game:GetService("RunService")
local camera = workspace.CurrentCamera
-- Recoil function that takes the amount to recoil and how quickly it will fade out
local function Recoil(amount, fade)
-- connect to the heartbeat function
local connection = nil
connection = runService.Heartbeat:Connect(function(deltaTime)
-- move the camera by amount
camera.CFrame *= CFrame.Angles(amount, 0, 0)
-- reduce amount
amount -= fade * deltaTime
-- if amount is still more then 0 exit the function and wait for next heartbeat
if amount > 0 then return end
-- amount is now less or equal to 0 so lets disconnect this function
connection:Disconnect()
end)
end
-- lets make a recoil with a amount of 0.2 and a fade speed of 0.5 (play around with these numbers to make it feel how you like)
Recoil(0.2, 0.5)