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

This is better since this way you can actually stop the connection.

Okay, I’ll test that right now.

I’ve never really used these kinds of connections before, how would I implement this into my script?

Would I do

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

?

This is unnecessary just store this on a variable like local RunService = game:GetService("RunService").

I know. I’ll do that right now

By the way it works, the camera is still constantly spinning though. Any idea on an in check to see if it should be done or not? This might be because I forgot to play the tween… whoops

You could try to print if the connection is still running. If it still running then the tween does not have a problem it’s the connection still not disconnected.

1 Like

Ok so the camera locks in place and rotates to the left a bit, then locks back onto the character and starts spinning, here is the code.

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


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,0,0)}):Play()
			Connection:Disconnect()
		else
			TS:Create(Camera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(10),0)}):Play()
			Connection = RS.Heartbeat:Connect(function()
				Camera.CFrame = Camera.CFrame * CFrame.Angles(0,math.rad(10),0)
			end)
		end
		Tilting = not Tilting
	end
end)

That’s because you have to change the Camera’s type to scriptable.

I changed it to scriptable and it no longer locks onto the character at all until you press E again

That’s because scriptable disables the built-in camera module.

So how would I lock it on to the character while rotating it, or re enable the camera module? Although I guess that defeat the purpose of “scriptable” doesn’t it.

You would instead use the HumanoidRootPart/Head’s position:

CFrame.Angles(0, math.rand(10), 0) * HumanoidRootPart.Position

Zoom in and out no longer work so you would have to modify that yourself aswell.

Ok, so the heartbeat, instead of setting the cameras position, it multiplies it.

I think this is the reason why it’s spinning, and will also fling the camera into the air

If I remove the second “Camera.CFrame” then it won’t fling into the air but it stills spins, not in third person though. But it is now offset from the correct position of the character.

As I have said you would want to use the humanoid’s root part not the camera.

I can’t use the HRP’s position, I have to use it’s CFrame, would this cause an issue (The reason i have to use it is the script will break otherwise)

Not the CFrame the position, if you want to you could use the HumanoidRootPart’s CFrame.

1 Like

The can’t use the HRP’s Position “Unable to assign property CFrame. CoordinateFrame expected, got Vector3”

Instead of multiply on CFrame.Angles(0, math.rand(10), 0) * HumanoidRootPart.Position try addition.

1 Like