Help with Camera CFrame.Angles

I’ve tried tilting the camera on the z axis but it doesnt seem to work unless in Scriptable CameraType which doesnt work out for me when making recoil, I am not asking for recoil on the X and Y axis, just the Z. this is the script I have currently.

2 Likes
Old reply

I think you should take out the line

workspace.CurrentCamera.CameraType = "Custom"

Never mind, move

workspace.CurrentCamera.CameraType = "Custom"

after

wait()

I tested it, it seems to work.

So the player is just to leave their camera behind while their player walks away? Its not a cutscene or anything that requires the camera to be stationary.

ok so theres still a problem, it still keeps the camera inplace until it is done, it makes it a bit choppy

It’s choppy due to the fact that you’re using wait which is 0.03 seconds, if you’re running at 60 FPS which is what roblox is capped at, then you will be moving the camera every other frame.

Use RunService.RenderStepped:Wait() instead of wait
Note that your Camera will now turn twice as fast, so you may want to divide the amount your rad is, to half. 1.75.

I have a question, is wait affected by fps just like renderstepped’s wait?

You don’t need to change ur CameraType. There’s probably better ways to achieve this but here’s a simple solution.

local cam = workspace.CurrentCamera
local RS = game:GetService("RunService")

function stabRecoil()
	local shakeDuration = 10/60
	local maxAngle = 5
	local render;
	local start = tick()
	
	render = RS.RenderStepped:connect(function(dt)
		local elapsed = tick() - start
		if elapsed > shakeDuration then --disconnect to save memory
			render:disconnect()
		elseif elapsed < shakeDuration/2 then --start recoil
			local alpha = elapsed/(shakeDuration/2)
			cam.CFrame *= CFrame.Angles(0, 0, math.rad(maxAngle * alpha))
		else --bring the recoil back
			local alpha = (shakeDuration - elapsed)/(shakeDuration/2)
			cam.CFrame *= CFrame.Angles(0, 0, math.rad(maxAngle * alpha))
		end
	end)
end

--when u needa do recoil
stabRecoil()

I believe wait will wait until the next frame, so it would be affected, yes.

However all Camera related things should be handled with RenderStepped, you can get the deltatime if you want to ensure it moves in accordance with your framerate.