Need help with tilting camera

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to smoothly tilt the camera on the z-axis based on player mouse movement.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is Tweening the camera makes it ignore input until tween is finished and ends up being jittery and unuseable, i tried using scriptable camera type and it also ignores player input.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    As said i tried tweening and using scriptable camera type and yes i did look it up alot on the forums i only saw 1 similar post but there was no solution they just said they made a custom camera module and idk how to do that.

My code so far looks like this:

local InputService = game:GetService('UserInputService')
local TweenService = game:GetService('TweenService')


local cam = workspace.CurrentCamera


local tweenInfo = TweenInfo.new(1/30, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

local minimumDeltaToRoll = 5
local deltaDiv = 400

local tween

InputService.InputChanged:Connect(function(input)
	
	
	if (tween) then
		tween:Pause()
	end
	
	
	if (input.UserInputType == Enum.UserInputType.MouseMovement) then
		
		
		
		local xDelta = input.Delta.X
		
		if (math.abs(xDelta) > minimumDeltaToRoll) then
			
			local rollCFrame = CFrame.fromAxisAngle(Vector3.zAxis, -xDelta/deltaDiv)
		
			tween = TweenService:Create(cam, tweenInfo, { CFrame = cam.CFrame * rollCFrame }):Play()
		end
	end
end)
2 Likes


This video shows the effect i’m trying to achieve btw. The subtle view tilt when moving camera side to side.

I usually handle camera movement with a RenderStepped / Heartbeat function and a Lerp ( my own tweening style thing )
What do you have so far?
Does it rotate correctly if it wasn’t jittery and ignoring input?

1 Like

Yes, it rotates how i want but the problem is that im tweening the camera. Do you know how i could detect mouse delta from renderstepped?

I am not sure what that is
Is that the distance on the screen that the mouse moved?

Yes, it is. I actually almost figured it thanks to your run service suggestion, i just need to figure out the lerping.

local InputService = game:GetService('UserInputService')
local RunService = game:GetService('RunService')


local cam = workspace.CurrentCamera



local minimumDeltaToRoll = 5
local deltaDiv = 100
local lerpSpeed = 0.2

local xDelta = 0
local alpha = 0

InputService.InputChanged:Connect(function(input)
	
	if (input.UserInputType == Enum.UserInputType.MouseMovement) then
		
		if (math.abs(input.Delta.X) > minimumDeltaToRoll) then
			
			xDelta = input.Delta.X
			alpha = 0
			
		else
			xDelta = 0
		end
	end
end)

RunService.RenderStepped:Connect(function(dt)
	
	alpha += dt*lerpSpeed
	
	local rollCFrame = CFrame.fromAxisAngle(Vector3.zAxis, -xDelta/deltaDiv)
	cam.CFrame = cam.CFrame:Lerp(cam.CFrame*rollCFrame, alpha)
end)
2 Likes

Oh nice! What does it do right now?


Looks pretty good just a bit of tweaking left to make it behave properly. Thank you for the quick suggestion i was looking at forums for a while lol.

1 Like

Niceee glad I could help It looks really good! and will probably get better! Gl bro

1 Like

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