local J=1 local s=.6 local q=.5 local d=.4 local Y=.25 local V=playerService.LocalPlayer local g=workspace.CurrentCamera local w=V:GetMouse()local n=V.Character or V.CharacterAdded:wait()local A=n:WaitForChild("\072\117\109\097\110\111\105\100")local U=A.RigType==Enum.HumanoidRigType.R6 local I=n.Head local k=n.HumanoidRootPart local P=U and n.Torso or n.UpperTorso local B=U and P.Neck or I.Neck local o=not U and P.Waist local G=B.C0 local N=not U and o.C0 B.MaxVelocity=.33333333333333 runService.RenderStepped:ConnectParallel(function()if P and(I and((U and B or B and o)and g.CameraSubject==A))then task.desynchronize()local V=g.CFrame local w=I.CFrame local n=P.CFrame.lookVector local A=(w.p-V.p).magnitude local k=w.Y-V.Y local D=math.asin(k/A)task.synchronize()local u=((w.p-V.p).Unit:Cross(n)).Y if U then B.C0=B.C0:lerp(G*CFrame.Angles((-1*D)*s,0,(-1*u)*J),Y)else B.C0=B.C0:lerp(G*CFrame.Angles(D*s,(-1*u)*J,0),Y)o.C0=o.C0:lerp(N*CFrame.Angles(D*d,(-1*u)*q,0),Y)end end end)
-- Variables
local headHorFactor = 1
local headVerFactor = 0.6
local bodyHorFactor = 0.5
local bodyVerFactor = 0.4
local updateSpeed = 0.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)
