wait(.1)local b=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local S=game.Workspace.CurrentCamera local G=game.Players.LocalPlayer local g=G.Character local f=g.Head local r=g.Torso local d=g.HumanoidRootPart local a=d.RootJoint local K=r.Neck S.FieldOfView=90 S.CameraType="\083\099\114\105\112\116\097\098\108\101"b.MouseBehavior=Enum.MouseBehavior.LockCenter local q=Vector3.new local s=CFrame.new local w=(s()).components local Q=(s()).inverse local u=CFrame.fromAxisAngle local v,Y=math.atan,math.atan2 local D=math.acos local function A(b)local S=b.z return S*S<.99999 and(q(b.y,-b.x,0)).unit*D(-S)or q()end local function i(b,S,G)local g=b-b.p local f=(Q(g)*S).unit local r=f.z return r*r<.99999 and g*u(q(f.y,-f.x,0),D(-r)*(G or 1))or g end local function X(b,S)local G=b.unit local g=G.z return g*g<.99999 and u(q(G.y,-G.x,0),D(-g)*(S or 1))or s()end local function n(b,S,G)local g=(Q(b)*S).unit local f=g.z return f*f<.99999 and b*u(q(g.y,-g.x,0),D(-f)*(G or 1))or b end local N=.005 local F=Vector3.new(0,0,0)local function c(b)local S,G=b.x,b.z return v(b.y/(S*S+G*G)^.5),-Y(S,-G)end local function C(b)local S=b.z return Y(b.y,-S),-Y(b.x,-S)end local function o(b)if b.UserInputType==Enum.UserInputType.MouseMovement then local S,G=b.Delta.x*N,b.Delta.y*N local g=S*S+G*G if g>0 then F=(i(d.CFrame,F)*u(q(-G,-S,0),g^.5)).lookVector end local f=d.CFrame-d.Position local r=f:inverse()*F local a,K=C(r)if a<-1.4391666666667 then local b,S,G,g=r.y,r.z,math.cos(-1.4391666666667-a),-math.sin(-1.4391666666667-a)S,b=S*G-b*g,S*g+b*G F=f*q(r.x<0 and-((1-b*b)-S*S)^.5 or((1-b*b)-S*S)^.5,b,S)elseif a>1.4391666666667 then local b,S,G,g=r.y,r.z,math.cos(1.4391666666667-a),-math.sin(1.4391666666667-a)S,b=S*G-b*g,S*g+b*G F=f*q(r.x<0 and-((1-b*b)-S*S)^.5 or((1-b*b)-S*S)^.5,b,S)end end end local M=G:GetMouse()local m=-0.5 M.KeyDown:connect(function(b)if b=="\101"then m=-0.5 elseif b=="\113"then m=-0.5 end end)b.InputChanged:connect(o)K.C1=s()local t local z=1.0471966666667 local E=0 local function O()S.CameraType="\083\099\114\105\112\116\097\098\108\101"local b,G=F.x,F.z local f,r=d.Velocity.x,d.Velocity.z if f*f+r*r>4 and b*f+G*r<(-0.5*(b*b+G*G)^.5)*(f*f+r*r)^.5 then z=math.min(z*.9,math.abs(E*.9))else z=z*.1+.942477 end local a,w=c((d.CFrame-d.Position):inverse()*F)if w>z then d.CFrame=d.CFrame*CFrame.Angles(0,w-z,0)elseif w<-z then d.CFrame=d.CFrame*CFrame.Angles(0,w+z,0)end t,E=c((d.CFrame-d.Position):inverse()*F)local Q=X((d.CFrame-d.Position):inverse()*F,1)K.C0=(CFrame.new(0,1,0)*Q)*CFrame.new(0,.5,0)local u=n(d.CFrame*s(0,1,0),d.CFrame*q(0,1,0)+F)*CFrame.new(0,.825,0)if m==8 then local b,G=Workspace:findPartOnRay(Ray.new(u.p,u.lookVector*-8),g)S.CoordinateFrame=u*CFrame.new(0,0,(G-u.p).magnitude)else S.CoordinateFrame=u*CFrame.new(0,0,m)end end;(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:connect(O)

wait(.1)
local InputService=game:GetService("UserInputService")
local Camera=game.Workspace.CurrentCamera
local Player=game.Players.LocalPlayer
local Character=Player.Character
local Head=Character.Head
local Torso=Character.Torso
local RootPart=Character.HumanoidRootPart
local RootJoint=RootPart.RootJoint
local Neck=Torso.Neck
Camera.FieldOfView=90
Camera.CameraType="Scriptable"
InputService.MouseBehavior = Enum.MouseBehavior.LockCenter



local v3=Vector3.new
local cf=CFrame.new
local components=cf().components
local inverse=cf().inverse
local fromAxisAngle=CFrame.fromAxisAngle
local atan,atan2=math.atan,math.atan2
local acos=math.acos

local function toAxisAngleFromVector(v)
	local z=v.z
	return z*z<0.99999 and v3(v.y,-v.x,0).unit*acos(-z) or v3()
end

local function AxisAngleLookOrientation(c,v,t)--CFrame,Vector,Tween
	local c=c-c.p
	local rv=(inverse(c)*v).unit
	local rz=rv.z
	return rz*rz<0.99999 and c*fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or c
end

local function AxisAngleLookNew(v,t)--CFrame,Vector,Tween
	local rv=v.unit
	local rz=rv.z
	return rz*rz<0.99999 and fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or cf()
end

local function AxisAngleLook(c,v,t)--CFrame,Vector,Tween
	local rv=(inverse(c)*v).unit
	local rz=rv.z
	return rz*rz<0.99999 and c*fromAxisAngle(v3(rv.y,-rv.x,0),acos(-rz)*(t or 1)) or c
end




local Sensitivity=0.005


local CameraDirection=Vector3.new(0,0,0)

local function EulerAnglesYX(l)
	local x,z=l.x,l.z
	return atan(l.y/(x*x+z*z)^0.5),-atan2(x,-z)
end

local function AnglesXY(l)
	local z=l.z
	return atan2(l.y,-z),-atan2(l.x,-z)
end

local function MouseMoved(Input)
	if Input.UserInputType==Enum.UserInputType.MouseMovement then
		local dx,dy=Input.Delta.x*Sensitivity,Input.Delta.y*Sensitivity
		local m2=dx*dx+dy*dy
		if m2>0 then
			CameraDirection=(AxisAngleLookOrientation(RootPart.CFrame,CameraDirection)*fromAxisAngle(v3(-dy,-dx,0),m2^0.5)).lookVector
		end
		local RootOrientation=RootPart.CFrame-RootPart.Position
		local RelativeDirection=RootOrientation:inverse()*CameraDirection
		local AngX,AngY=AnglesXY(RelativeDirection)--RootOrientation:inverse()*
		if AngX<-1.57*11/12 then
			local y,z,c,s=RelativeDirection.y,RelativeDirection.z,math.cos(-1.57*11/12-AngX),-math.sin(-1.57*11/12-AngX)
			z,y=z*c-y*s,z*s+y*c
			CameraDirection=RootOrientation*v3(RelativeDirection.x<0 and -(1-y*y-z*z)^0.5 or (1-y*y-z*z)^0.5,y,z)
		elseif AngX>1.57*11/12 then
			local y,z,c,s=RelativeDirection.y,RelativeDirection.z,math.cos(1.57*11/12-AngX),-math.sin(1.57*11/12-AngX)
			z,y=z*c-y*s,z*s+y*c
			CameraDirection=RootOrientation*v3(RelativeDirection.x<0 and -(1-y*y-z*z)^0.5 or (1-y*y-z*z)^0.5,y,z)
		end
	end
end

local Mouse=Player:GetMouse()

local Zoom=-0.5

Mouse.KeyDown:connect(function(k) 
	if k=="e" then 	
		Zoom=-0.5
	elseif k=="q" then
		Zoom=-0.5
	end
end)

InputService.InputChanged:connect(MouseMoved)

Neck.C1=cf()

local _
local DirectionBound=3.14159/3
local CurrentAngY=0

local function CameraUpdate()
	Camera.CameraType="Scriptable"
	local cx,cz=CameraDirection.x,CameraDirection.z
	local rvx,rvz=RootPart.Velocity.x,RootPart.Velocity.z
	if rvx*rvx+rvz*rvz>4 and cx*rvx+cz*rvz<-0.5*(cx*cx+cz*cz)^0.5*(rvx*rvx+rvz*rvz)^0.5 then
		DirectionBound=math.min(DirectionBound*0.9,math.abs(CurrentAngY*0.9))
	else
		DirectionBound=DirectionBound*0.1+3.14159/3*0.9
	end
	local AngX,AngY=EulerAnglesYX((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection)
	if AngY>DirectionBound then
		RootPart.CFrame=RootPart.CFrame*CFrame.Angles(0,AngY-DirectionBound,0)
	elseif AngY<-DirectionBound then
		RootPart.CFrame=RootPart.CFrame*CFrame.Angles(0,AngY+DirectionBound,0)
	end
	_,CurrentAngY=EulerAnglesYX((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection)
	local CameraOrientation=AxisAngleLookNew((RootPart.CFrame-RootPart.Position):inverse()*CameraDirection,1)
	Neck.C0=CFrame.new(0,1,0)*CameraOrientation*CFrame.new(0,0.5,0)
	local PreCam=AxisAngleLook(RootPart.CFrame*cf(0,1,0),RootPart.CFrame*v3(0,1,0)+CameraDirection)*CFrame.new(0,0.825,0)
	if Zoom==8 then
		local Part,Position=Workspace:findPartOnRay(Ray.new(PreCam.p,PreCam.lookVector*-8),Character)
		Camera.CoordinateFrame=PreCam*CFrame.new(0,0,(Position-PreCam.p).magnitude)
	else
		Camera.CoordinateFrame=PreCam*CFrame.new(0,0,Zoom)
	end
end

game:GetService("RunService").RenderStepped:connect(CameraUpdate)
