Smoothing out camera roll/tilt with mouse momentum

i’ve been trying to implement camera rolling with momentum and i’ve got the groundworks for it but i can’t seem to smooth it out. it rolls, yes, but it’s janky and doesn’t look great.

below is not my exact codeblock because it is in a module but there are no major differences.

local Camera = workspace.CurrentCamera
local CameraTiltPower = 0.15

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

RunService:BindToRenderStep("CameraRoll", Enum.RenderPriority.Camera.Value, function()
	if not Camera then return end

	local mouseDelta = UserInputService:GetMouseDelta()
	local tiltAngle = CFrame.Angles(0, 0, math.rad(mouseDelta.X * -CameraTiltPower))

	Camera.CFrame = Camera.CFrame * tiltAngle
end)

I tried making the mouse delta change slowly so the tilt is more noticeable, Im not sure if this is for your liking but here is the code:

local Camera = workspace.CurrentCamera
local CameraTiltPower = 0.15

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local mouseDelta = Vector2.zero

RunService:BindToRenderStep("CameraRoll", Enum.RenderPriority.Camera.Value, function()
	if not Camera then return end

	mouseDelta = mouseDelta:Lerp(UserInputService:GetMouseDelta(), 0.1)
	local tiltAngle = CFrame.Angles(0, 0, math.rad(mouseDelta.X * -CameraTiltPower * 15))

	Camera.CFrame = Camera.CFrame * tiltAngle
end)
1 Like

not entirely what i’m going for, as im happy with its current tilt, i am just trying to smooth the camera as its jittery

i’ve been at it for a bit and it seems this has produced the results i wanted

local Camera = workspace.CurrentCamera

local CameraTiltPower = 0.5
local CameraSmoothing = 10
local CurrentTiltAngle = 0 -- don't edit

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

RunService:BindToRenderStep("CameraRoll", Enum.RenderPriority.Camera.Value, function(deltaTime)
		if not Camera then return end

		local mouseDelta = UserInputService:GetMouseDelta()
		local targetTiltAngle = math.rad(mouseDelta.X * -CameraTiltPower)
		
		CurrentTiltAngle = CurrentTiltAngle + (targetTiltAngle - CurrentTiltAngle) * CameraSmoothing * deltaTime

		local tiltCFrame = CFrame.Angles(0, 0, CurrentTiltAngle)
		Camera.CFrame = Camera.CFrame * tiltCFrame
	end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.