How do I make the camera tilt smoothly and stay on the player?

  1. What do I want to achieve?

I want to figure out how to make the camera tilt smoothly, probably with a tween, while also not being locked in place.

  1. What is the issue?

Every time I have attempted something like this the camera is either choppy, gets locked in place, or doesn’t work at all.

  1. What solutions have I tried so far?

I have tried solutions multiple times on this forum but none of them were what I was looking for.

I would like an example script that would show how to do this, I am not asking for an entire system I am just asking for, maybe a button press rotates the camera a little bit or something, I could just edit it from there, any and all help is appreciated, thanks.

1 Like

When does the camera tilt? Are you talking about the camera wobble effect?

1 Like

Ah, no, not that. When a button is pressed the camera would rotate (It doesn’t matter where since it could just be edited afterwards.), It doesn’t have to be on a button press, it should just be there’s a time where it’s tilted and not titled. It would not be a constantly moving thing, it would only move until the tween would finish

1 Like

Then this would be very simple just get the CFrame of the camera then multiply it with CFrame.Angles, of course this would be connected to a loop.

1 Like

Wouldn’t it just teleport to that rotation though? I also should have mentioned I would like to use easing styles.

You mean like this right?

game:GetService("RunService").RenderStepped:Connect(function()
	Camera.CFrame = Camera.CFrame * CFrame.Angles(0,0,Angle)
end)
1 Like

Just increase the x, y or z of the CFrame.Angles.

1 Like

So something like this?

game:GetService("RunService").RenderStepped:Connect(function()
	Camera.CFrame += Camera.CFrame * CFrame.Angles(0,0,Angle)
end)

And use an if check to see if it’s at a certain value (or higher) and stop it if it is?

Yeah if you want to check what’s the orientation of the camera just use Camera.CFrame:ToOrientation() this should give you the x, y and z in radians.

How would I replicate the effect of an easing style? (Quad and Back are the main ones I would like to use)

Also wouldn’t this lock the camera in place?

TweenService. TweenService.Create(Camera, TweenInfo.new(), {CFrame = NewCFrame}).

No since we are multiplying it by the current CFrame.

I think that might overlap with the runservice but I’ll try it.

Do I put the tween inside the runservice?

Of course you define it outside the connection so you only get the reference/service once.

Oh ok I thought you would put it in, I thought that might have been the problem this whole time lol

Ok so right now it does not move the camera at all, the angle is just a test number right now

local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local Tilting = false
local Cooldown = false
local Camera = game.Workspace.CurrentCamera


UIS.InputBegan:Connect(function(i,g)
	if i.KeyCode == Enum.KeyCode.E and not g and Cooldown == false then
		Cooldown = true
		delay(2,function()
			Cooldown = false
		end)
		if Tilting == true then
			TS:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = Camera.CFrame * CFrame.Angles(0,100,0)})
		elseif Tilting == false then
			TS:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = Camera.CFrame * CFrame.Angles(0,0,0)})
		end
		Tilting = not Tilting
	end
end)
game:GetService("RunService").RenderStepped:Connect(function()
	if Tilting == true then
		Camera.CFrame = Camera.CFrame * CFrame.Angles(0,100,0)
	end
end)

If I remove the ToOrientation check, I spin around constantly (In first person).

Angles requires a number in radians or from -pi(3.14…) to pi(3.14…) so it would be math.rad(100) 100 is the degree you want to multiply it with.

Ok. Is there a way to stop the camera from constantly spinning (But have it still rotating)

local Connection

Button:OnClick(function()
    if Toggle then
        Connection:Disconnect()
    else
        Connection = Heartbeat:Connect(...)
    end
end)

Isn’t this just what the “Tilting” Value does?

game:GetService("RunService").Heartbeat:Connect(function()
	if Tilting == true then
		Camera.CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(10),0)
	end
end)