Camera View Rolling/Tilting not Working

  1. What do I want to achieve?
    I want to make a script where when the player presses “D” to walk side ways, the PLAYER’S camera tilts on the “z” axis a little

  2. Whats the issue?
    Im not the best in scripting and this is my first time messing around with camera CFrame, yet this script does not work the way i want it to, it continuously tilts the camera (only on the “x” and “y” axis though, the “z” axis doesn’t work, please help with this) so the camera always ends up looking up at the sky

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local UserInputService = game:GetService("UserInputService")

function onInputChanged(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.D then
		if inputObject.UserInputState == Enum.UserInputState.Begin then
			while UserInputService:IsKeyDown(Enum.KeyCode.D) do
				Camera.CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(25))

  1. What have I tried so far?
    I have looked on a bunch of other dev forum topics, no one seems to say and/or know how to fix it so the camera can tilt on the “z” axis, I have tried to figure out CFrame:ToOrientation, wich, nothing I did worked, and more stuff that I cant remember.

Please help, I mostly just want to fix the tilting, because it’s wrong, the tilting on the “z” axis not working and I want to make the tilting smooth.

1 Like

This rotates the camera on the world’s Z axis, not it’s own local Z axis. So if you’re looking in the direction of the world’s X axis, that would cause the camera to pitch instead of roll.

Try Camera.CFrame *= Camera.CFrame:ToWorldSpace(CFrame.Angles(0, 0, rad(25)))

it didn’t work, the

has a little error line under it and in the output I get this error: Players.cheesymuffin8.PlayerScripts.ViewRolling:11: attempt to call a nil value

The line of code @cheesymuffin8 provided has a small syntax error/probable typo. it should be

Camera.CFrame *= Camera.CFrame:ToWorldSpace(CFrame.Angles(0, 0, math.rad(25)))
1 Like

this works, just not the right way, it was probably my wording, but i dont want the camera to rotate around the player, i want the camera to tilt, Example, if I were to look at something with my head tilted sideways irl.

this is what i got from the script above btw (not what i want) and (im holding D btw in the video)

I also only what the camera to tilt a little bit

Here’s what I created in like 30 mins or so.


local cam = workspace.CurrentCamera
local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local char

local ad = {0,0}

uis.InputBegan:Connect(function(inp, gpe)
	if gpe then return end
	if inp.KeyCode == Enum.KeyCode.D then
		ad[1] = 1
	elseif inp.KeyCode == Enum.KeyCode.A then
		ad[2] = 1
	if inp.KeyCode == Enum.KeyCode.D then
		ad[1] = 0
	elseif inp.KeyCode == Enum.KeyCode.A then
		ad[2] = 0

if player.Character then
	char = player.Character
	char = c

cam.CameraType = Enum.CameraType.Scriptable
	cam.CFrame = char.Head.CFrame * CFrame.Angles(0, 0, (ad[2]-ad[1])*math.pi*0.1)


		local hum = Char:WaitForChild("Humanoid")
		hum.AutoRotate = false

That is the same thing as CFrame * CFrame, so Camera.CFrame *= CFrame.Angles(0,0,math.rad(25)) and Camera.CFrame *= Camera.CFrame:ToWorldSpace(CFrame.Angles(0, 0, rad(25))) are equivalent.

it works, one small thing, I can’t turn my camera anymore, and would there be a way to make the camera tilt smoothly?

Smoothly tweening between 2 or more goal cframes that can change at random is something I’ve been looking into trying to do consistently timing-wise across various applications.
The basic idea is to use TweenService to tween it smoothly to the goal cframe. The goal cframe in the code I posted is set instantly. The issue I have is calculating the time it should take to get there. The time it takes to get there is based on where it currently is.

My problem aside, if you want something simple, then just use 0.5 seconds and it will look smooth.

As for turning the character, I don’t know yet.

Found this line in the PlayerModule.CameraModule
Changing this line therefore creating a “modified” camera script would mean you can’t really use TweenService anymore. However you could move your character around while tilting the CFrame.

I believe this line is being ran in a RenderStepped variation.

1 Like

do you think using lerp would work?

I did the following:

And then removed my prior code.
And it works but not smoothly.
Yes Lerp should work but the math is hard imo.

1 Like

Alright I’m gonna get off the forums for a while but here’s what I managed to do so far.

Also if you don’t already know how to get the PlayerModule and CameraModule stuff, you simply press play in Studio and then look inside StarterPlayer.StarterPlayerScripts and Roblox’s scripts should be automatically inserted if it wasn’t there before.

1 Like

I’m gonna be honest, your script is alien language to me because i am a very basic scripter, but it works, would there be a way to make the camera tilt a bit faster?


local ad = {0, 0, 0.5, 0}


local ad = {0, 0, 0.4, 0}

or whatever value you want. It’s the time in seconds to get to the goal cframe.


is the 3rd value in the array ad. And


is the 4th value.
The code treats the first two values as left/right tilt values to determine the goal cframe, which is just a modified cframe from whatever Roblox’s script is giving us.
The 3rd value is the time to get to the goal cframe.
Finally the 4th value is the current position of the cframe. So if ad[4] = ad[3] then you are at goal cframe, but if ad[4] = 0 then you are at non-tilting cframe.
ad[3] and ad[4] are both numbers in seconds.
ad[1] and ad[2] are basically booleans but used as integers (subtraction and multiplication)

1 Like

dt is the time elapsed between frames.

1 Like