Making smooth recoil with CFrame

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

Camera.CFrame *= CFrame.Angles(math.rad(15), 0, 0)
Camera.CFrame *= CFrame.Angles(math.rad(15), 0, 0)

you’re moving along the x axis try moving along the y axis if you want it to go upwards

Camera.CFrame *= CFrame.Angles(0, math.rad(15), 0)

You need that for sure, the cframe will reset to 0 if he does that

oh, thanks for pointing out my mistake i mistyped it, edited!

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)
4 Likes