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

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)
	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)
	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)
	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,1)

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)
