local p=1 local y=.6 local h=.5 local X=.4 local K=.25 local N=playerService.LocalPlayer local U=workspace.CurrentCamera local V=N:GetMouse()local d=N.Character or N.CharacterAdded:wait()local w=d:WaitForChild("\072\117\109\097\110\111\105\100")local P=w.RigType==Enum.HumanoidRigType.R6 local m=d.Head local g=d.HumanoidRootPart local u=P and d.Torso or d.UpperTorso local t=P and u.Neck or m.Neck local L=not P and u.Waist local T=t.C0 local I=not P and L.C0 t.MaxVelocity=.33333333333333 runService.RenderStepped:ConnectParallel(function()if u and(m and((P and t or t and L)and U.CameraSubject==w))then task.desynchronize()local N=U.CFrame local V=m.CFrame local d=u.CFrame.lookVector local w=(V.p-N.p).magnitude local g=V.Y-N.Y local q=math.asin(g/w)task.synchronize()local v=((V.p-N.p).Unit:Cross(d)).Y if P then t.C0=t.C0:lerp(T*CFrame.Angles((-1*q)*y,0,(-1*v)*p),K)else t.C0=t.C0:lerp(T*CFrame.Angles(q*y,(-1*v)*p,0),K)L.C0=L.C0:lerp(I*CFrame.Angles(q*X,(-1*v)*h,0),K)end end end)

local headHorFactor = 1
local headVerFactor = .6
local bodyHorFactor = .5
local bodyVerFactor = .4
local updateSpeed = .5 / 2

local plr = playerService.LocalPlayer
local cam = workspace.CurrentCamera
local mouse = plr:GetMouse()

local char = plr.Character or plr.CharacterAdded:wait()
local hum = char:WaitForChild("Humanoid")
local isR6 = hum.RigType == Enum.HumanoidRigType.R6
local head = char.Head
local root = char.HumanoidRootPart
local torso = isR6 and char.Torso or char.UpperTorso
local neck = isR6 and torso.Neck or head.Neck
local waist = not isR6 and torso.Waist

local neckC0 = neck.C0
local waistC0 = not isR6 and waist.C0

neck.MaxVelocity = 1/3


runService.RenderStepped:ConnectParallel(function()
	

	-- Check if every required body part exists and whether the CurrentCamera's CameraSubject is the Humanoid
	if torso and head and ((isR6 and neck) or (neck and waist)) and cam.CameraSubject == hum then
		task.desynchronize()
		local camCF = cam.CFrame
		local headCF = head.CFrame

		local torsoLV = torso.CFrame.lookVector

		local dist = (headCF.p - camCF.p).magnitude
		local diff = headCF.Y - camCF.Y

		local asinDiffDist = math.asin(diff / dist)
		task.synchronize()
		local whateverThisDoes = ((headCF.p - camCF.p).Unit:Cross(torsoLV)).Y

		if isR6 then
			neck.C0 = neck.C0:lerp(neckC0 * CFrame.Angles(-1 * asinDiffDist * headVerFactor, 0, -1 * whateverThisDoes * headHorFactor), updateSpeed)
		else
			neck.C0 = neck.C0:lerp(neckC0 * CFrame.Angles(asinDiffDist * headVerFactor, -1 * whateverThisDoes * headHorFactor, 0), updateSpeed)
			waist.C0 = waist.C0:lerp(waistC0 * CFrame.Angles(asinDiffDist * bodyVerFactor, -1 * whateverThisDoes * bodyHorFactor, 0), updateSpeed)
		end

	end
	
end)
