Making camera adapt to character's upvector

I have been working on a modification of EgoMoose’s Gravity Controller, which works in a zone based system. However, the camera does not work. I tried making a custom camera script to see if it could work, however it was quite glitchy, and I dont know how to improve it. SCRIPT:

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local head = script.Parent:WaitForChild("Head")
local subject = script:WaitForChild("Subject")
subject.Parent = workspace
camera.CameraType = Enum.CameraType.Scriptable
subject.Position = head.Position
local WEIGHT = 6

local function camupdate()
	camera.CFrame = rootPart.CFrame - rootPart.CFrame.LookVector * 4
RunService:BindToRenderStep("camupdate", Enum.RenderPriority.Camera.Value, camupdate)

Try attempting to hold any other movement key except W. You can see it doesn’t really work well.