Camera Tilt Problem

I was trying to make a tilt camera when player moves right or left and i just searched some resources.

I checked this thread: How to tilt camera smoothly based on the players movement

Then i decide to change some settings to make more smoother. But it did’nt work and i opened the thread here: Having a Tween problem

After that, some helpful people tried to help me but i could’nt get the solution. As i mentioned in the thread, if it still does’nt work again (actually still it was’nt working) i could open thread in roblox studio bugs. But later i realized it was related to my script but i dont know how to do it and thats why im opening this thread.

If we come to my problem, i want to tilt the camera, when player goes left or right smoother. But it goes immediately, Here is the script:

-- this script in the startercharacterscript

local Player = game.Players.LocalPlayer
local Humanoid = Player.Character:WaitForChild("Humanoid")
local Camera = game.Workspace.CurrentCamera

local Debounce = false

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

local info = TweenInfo.new(2,Enum.EasingStyle.Linear)


local function doTween(degrees)
	local TweenCreate = TweenService:Create(Camera,info,{CFrame = Camera.CFrame * CFrame.Angles(0,0,math.rad(degrees))})
	TweenCreate:Play()
end


RunService.RenderStepped:Connect(function()
	
	if userInput:IsKeyDown(Enum.KeyCode.A) and userInput:IsKeyDown(Enum.KeyCode.D) then
		doTween(0)
	elseif userInput:IsKeyDown(Enum.KeyCode.A) then
		doTween(20)
	elseif userInput:IsKeyDown(Enum.KeyCode.D) then
		doTween(-20)
	else
		doTween(0)
	end
	
end)

If you try it, you will understand what is happening. And sorry if i reply so late. Thanks already.

Original poster here, here is a far more better script for camera tilt

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

local Player = Players.LocalPlayer
local Camera = workspace.CurrentCamera

local rad = math.rad
local Rot = CFrame.new()

local function GetRollAngle()
	local Character = Player.Character

	if not Character then
		return
	end

	local Cf = Camera.CFrame

	return -Cf.RightVector:Dot(Character.Humanoid.MoveDirection)
end

RunService:BindToRenderStep("RotateCameraInDirectionPlayerIsGoing", Enum.RenderPriority.Camera.Value + 1, function()
	local Roll = GetRollAngle() * 2
	Rot = Rot:Lerp(CFrame.Angles(0, 0, rad(Roll)),0.075)

	Camera.CFrame *= Rot
end)

This doesn’t require UIS, meaning that this works on all devices. Credits to @hashyyyyeryjrjej for the script!

3 Likes

It works, thanks so much! I think i will spend 2 days to figure out this how it works.

1 Like

Put it in startercharacterscripts, then it should work :slight_smile:

1 Like

Sorry for replying so late and bumping. I just said for figuring out how this script works and how to apply into my creations. Thanks

1 Like