You can write your topic however you want, but you need to answer these questions:
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.
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.
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)
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?
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)