Загрузка данных


local testing = false --set true if you want "CamPart" to be visible
local min = -10 --minimum distance
local max = 4 --maximum distance
local Rigidness = 0.6 --bigger number = faster movement, it would normally be 0.1-1, but it may vary depending on fps. DON'T SET TO < 0.1



local humanoid = script.Parent:WaitForChild("Humanoid")
local rootpart = script.Parent:WaitForChild("HumanoidRootPart")
local head = script.Parent:WaitForChild("Head")
local CamPart = Instance.new("Part")

CamPart.CanCollide = false
if not testing then 
	CamPart.Transparency = 1
	CamPart.Parent = script.Parent
else
	Instance.new("Highlight",CamPart).FillColor = Color3.new(0,0,1)
	CamPart.Parent = workspace
	local Part2 = Instance.new("Part",CamPart)
	Part2.Material = Enum.Material.Glass
	Part2.Size = Vector3.new(max,max,max)
	Part2.CanCollide = false
	Part2.Transparency = 1
	Part2.Shape = Enum.PartType.Ball
	Instance.new("Highlight",Part2)
end
CamPart.Anchored = true
CamPart.Position = head.Position
CamPart.FrontSurface = Enum.SurfaceType.Motor
CamPart.Shape = Enum.PartType.Ball
CamPart.Size = Vector3.new(3,3,3)
local pos
game["Run Service"].RenderStepped:Connect(function(dt)
	if CamPart.Position.Magnitude > 10000 or CamPart.Position.Magnitude < -10000 then
		CamPart.CFrame = workspace.CurrentCamera.CFrame
	end
	pos = head.Position
	CamPart.Position = CamPart.Position:Lerp(pos,Rigidness*(dt*10))
	CamPart.CFrame = CamPart.CFrame:Lerp(CFrame.lookAt(CamPart.Position,head.Position),Rigidness*(dt*10))
	local calc = (rootpart.CFrame+Vector3.new(0,1.1,0)):Inverse() * (CamPart.Position)
	if calc.Magnitude > max/2 then
		workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:Lerp(workspace.CurrentCamera.CFrame:Lerp(CFrame.lookAt(workspace.CurrentCamera.CFrame.Position,head.Position),Rigidness/(Rigidness*10)),Rigidness/(Rigidness*10))
	end
	if testing then
		CamPart.Part.CFrame = CamPart.CFrame
	end
	humanoid.CameraOffset = Vector3.new(math.clamp(calc.X,min,max),math.clamp(calc.Y,min,max),math.clamp(calc.Z,min,max))

end)