--// MAIN CODE


torso = character:WaitForChild("HumanoidRootPart")
joint = character:FindFirstChild("RootJoint", true)
baseC1 = joint.C1

cr = coroutine.resume
cc = coroutine.create

local function getangles()
	local side = torso.CFrame.RightVector:Dot(humanoid.MoveDirection)
	local front = torso.CFrame.LookVector:Dot(humanoid.MoveDirection)
	if frontenabled then
		return side, front*frontmultiplier
	else
		return side, 0
	end
end


humanoid.Died:connect(function()
	script.Disabled = true
end)


game:GetService("RunService").Heartbeat:Connect(function()
	local side, front = getangles()
	joint.C1 = joint.C1:Lerp(baseC1 * CFrame.Angles(math.rad(-front*maxtilt*(humanoid.WalkSpeed/8)),0,math.rad(side*maxtilt*(humanoid.WalkSpeed/16))), stiffness/50)
	
	local ctick = tick()
	if humanoid.MoveDirection.Magnitude > 0 then 

		cr(cc(function()
			local bobx = math.cos(ctick * 7.5) * .25
			local boby = math.abs(math.sin(ctick * 7.5)) * .25        

			local bob = Vector3.new(bobx, boby, 0)

			humanoid.CameraOffset = humanoid.CameraOffset:lerp(bob, .25)
		end))




	else 
		humanoid.CameraOffset = humanoid.CameraOffset * .75
	end
end)
