Custom camera not rotating

I’ve been trying to make this smooth camera that you can rotate with the arrow keys (planning to add sensitivity), but I can’t seem to make it rotate.
The camera only rotates a tiny bit before stopping.

Code:

RunServ.Heartbeat:Connect(function()
	Cam.CameraType = Enum.CameraType.Scriptable
	Cam.CFrame = Cam.CFrame:Lerp(CFrame.new(script.Parent:WaitForChild("HumanoidRootPart").Position + Vector3.new(0, 5, -25), script.Parent:WaitForChild("HumanoidRootPart").Position + Cam.CFrame.LookVector), .15)
end)
UserInputServ.InputBegan:Connect(function(Input, Processed)
	if not Processed then
		if Input.KeyCode == Enum.KeyCode.Right then
			local Rep = true
			local Con = UserInputServ.InputEnded:Connect(function(Input)
				if Input.KeyCode == Enum.KeyCode.Right then
					Rep = false
				end
			end)
			repeat Cam.CFrame = Cam.CFrame * CFrame.Angles(0, -math.rad(.1), 0) RunServ.RenderStepped:Wait() until not Rep
			Con:Disconnect()
			Rep = false
		end
	end
end)

Any help would be appreciated.

The reason it goes back is because in the the hearbeat function the camera cframe is being set back to cframe behind the humaoid root part.

2 Likes

I don’t get what you mean. It’s adding the LookVector to the position.
Can you explain?

Oh. I see what you mean. This did indeed fix the problem, but it looks like it’s in first person. I’m trying to get a third person camera.

In your heartbeat code add an additive cframe:

local turn = CFrame.Angles(0,0,0)

local rootpart = character:WaitForChild("HumanoidRootPart")

UIS.InputBegan:connect(function(input)
-- put his in repeating loop
turn = turn * CFrame.Angles(0,math.rad(5),0) -- on input, change our variable
end)


RunService.Heartbeat:connect(function()
Cam.CFrame = Cam.CFrame:Lerp(CFrame.new(rootpart.Position + Vector3.new(0, 5, -25), rootpart.Position + Cam.CFrame.LookVector) * turn, .15)
-- add turn variable to the mix
end)

Make sure to use variables so you don’t have to run something like character:WaitForChild(“HumanoidRootPart”) every single frame.

Reverts back to main position, even though it rotates. Basically the same thing but it rotates more.

Ah. Got it to work. Was my lerp math being messed up. Thanks for the help, everyone.