local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Player = game:GetService('Players').LocalPlayer
local Camera = game.Workspace.CurrentCamera
local Mouse = Player:GetMouse()
local Target = game.Workspace:WaitForChild('Part')
local LastMousePos = Mouse.X
local Holding = false
local DeltaMouse = 0
local Damping = 0.5
local TransferingState = false
local CurrentState = 'Default'
local ZoomStates = {
['Default'] = CFrame.new(5, 5, 10)
}
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = Target
function MoveStates(State, Speed)
local Speed = Speed or 0.1
TransferingState = true
CurrentState = 'Lerp'
for Index = 1, 20 do
ZoomStates[CurrentState] = ZoomStates[CurrentState]:lerp(ZoomStates[State], Speed/20)
wait()
end
TransferingState = false
CurrentState = State
end
local function RightChanged(actionName, actionInputState, actionInputObject)
if actionInputState == Enum.UserInputState.End then
Holding = false
elseif actionInputState == Enum.UserInputState.Begin then
Holding = true
end
end
local function GetDeltaMouseSpeed()
local DeltaMouseRecorder = coroutine.create(function()
while wait() do
DeltaMouse = LastMousePos - Mouse.X
LastMousePos = Mouse.X
end
end)
coroutine.resume(DeltaMouseRecorder)
end
local function CameraHandle()
GetDeltaMouseSpeed()
spawn(function()
local Index = 200
while wait() do
if not Holding then
Index = Index + math.rad(Damping)
Camera.CoordinateFrame = CFrame.new(Target.Position)
* CFrame.Angles(0, Index, 0)
* ZoomStates[CurrentState]
* CFrame.Angles(math.rad(-20), 0, 0)
else
local NewAngle = Index + (DeltaMouse * 0.005)
Index = NewAngle
Camera.CoordinateFrame = CFrame.new(Target.Position)
* CFrame.Angles(0, NewAngle, 0)
* ZoomStates[CurrentState]
* CFrame.Angles(math.rad(-20), 0, 0)
end
end
end)
end
game:GetService("ContextActionService"):BindAction("RightChanged", RightChanged, false, Enum.UserInputType.MouseButton2)
CameraHandle()
#code while wait(1) and x > madness do x = x - 0.01 end |