--!native local function safe_unpack(t, i) i = i or 1 if i <= #t then return t[i], safe_unpack(t, i + 1) end end local unpack = table.unpack or unpack or safe_unpack local function safe_get(global_name, default_val) local s, r = pcall(function() return getgenv()[global_name] end) if s and r then return r end return default_val end local cloneref = safe_get("cloneref", function(o) return o end) local getnilinstances = safe_get("getnilinstances", function() return {} end) local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local ContextActionService = game:GetService("ContextActionService") local StarterGui = game:GetService("StarterGui") local Workspace = game:GetService("Workspace") local TweenService = game:GetService("TweenService") local ScreenGui = Instance.new("ScreenGui") ScreenGui.Name = "AdvancedFreecamGUI" ScreenGui.ResetOnSpawn = false ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling local success, err = pcall(function() ScreenGui.Parent = game:GetService("CoreGui") end) if not success then ScreenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui") end local EXPANDED_SIZE = UDim2.new(0, 240, 0, 330) local MINIMIZED_SIZE = UDim2.new(0, 40, 0, 40) local ANIM_INFO = TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out) local MainFrame = Instance.new("Frame") MainFrame.Name = "MainFrame" MainFrame.Parent = ScreenGui MainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 35) MainFrame.BorderSizePixel = 0 MainFrame.Position = UDim2.new(0.1, 0, 0.1, 0) MainFrame.Size = EXPANDED_SIZE MainFrame.ClipsDescendants = true local MainCorner = Instance.new("UICorner") MainCorner.CornerRadius = UDim.new(0, 8) MainCorner.Parent = MainFrame local MainStroke = Instance.new("UIStroke") MainStroke.Parent = MainFrame MainStroke.Color = Color3.fromRGB(60, 60, 65) MainStroke.Thickness = 1 MainStroke.Transparency = 0.5 local TitleBar = Instance.new("Frame") TitleBar.Name = "TitleBar" TitleBar.Parent = MainFrame TitleBar.BackgroundColor3 = Color3.fromRGB(40, 40, 45) TitleBar.BorderSizePixel = 0 TitleBar.Size = UDim2.new(1, 0, 0, 40) TitleBar.BackgroundTransparency = 0 local TitleCorner = Instance.new("UICorner") TitleCorner.CornerRadius = UDim.new(0, 8) TitleCorner.Parent = TitleBar local TitleCover = Instance.new("Frame") TitleCover.Name = "TitleCover" TitleCover.Parent = TitleBar TitleCover.BackgroundColor3 = TitleBar.BackgroundColor3 TitleCover.BorderSizePixel = 0 TitleCover.Position = UDim2.new(0, 0, 1, -10) TitleCover.Size = UDim2.new(1, 0, 0, 10) TitleCover.ZIndex = 0 local TitleText = Instance.new("TextLabel") TitleText.Name = "Title" TitleText.Parent = TitleBar TitleText.BackgroundTransparency = 1 TitleText.Position = UDim2.new(0, 12, 0, 0) TitleText.Size = UDim2.new(1, -90, 1, 0) TitleText.Font = Enum.Font.GothamBold TitleText.Text = "Freecam Control" TitleText.TextColor3 = Color3.fromRGB(255, 255, 255) TitleText.TextSize = 16 TitleText.TextXAlignment = Enum.TextXAlignment.Left local ButtonsContainer = Instance.new("Frame") ButtonsContainer.Parent = TitleBar ButtonsContainer.BackgroundTransparency = 1 ButtonsContainer.Position = UDim2.new(1, -70, 0, 5) ButtonsContainer.Size = UDim2.new(0, 65, 0, 30) local CloseBtn = Instance.new("TextButton") CloseBtn.Name = "CloseBtn" CloseBtn.Parent = ButtonsContainer CloseBtn.BackgroundColor3 = Color3.fromRGB(200, 60, 60) CloseBtn.Position = UDim2.new(1, -30, 0, 0) CloseBtn.Size = UDim2.new(0, 30, 0, 30) CloseBtn.Font = Enum.Font.GothamBold CloseBtn.Text = "X" CloseBtn.TextColor3 = Color3.fromRGB(255, 255, 255) CloseBtn.TextSize = 14 CloseBtn.AutoButtonColor = false local CloseCorner = Instance.new("UICorner") CloseCorner.CornerRadius = UDim.new(0, 6) CloseCorner.Parent = CloseBtn local MinimizeBtn = Instance.new("TextButton") MinimizeBtn.Name = "MinimizeBtn" MinimizeBtn.Parent = ButtonsContainer MinimizeBtn.BackgroundColor3 = Color3.fromRGB(70, 70, 75) MinimizeBtn.Position = UDim2.new(1, -65, 0, 0) MinimizeBtn.Size = UDim2.new(0, 30, 0, 30) MinimizeBtn.Font = Enum.Font.GothamBold MinimizeBtn.Text = "-" MinimizeBtn.TextColor3 = Color3.fromRGB(255, 255, 255) MinimizeBtn.TextSize = 18 MinimizeBtn.AutoButtonColor = false local MinCorner = Instance.new("UICorner") MinCorner.CornerRadius = UDim.new(0, 6) MinCorner.Parent = MinimizeBtn local ContentFrame = Instance.new("Frame") ContentFrame.Name = "ContentFrame" ContentFrame.Parent = MainFrame ContentFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 35) ContentFrame.BackgroundTransparency = 1 ContentFrame.Position = UDim2.new(0, 0, 0, 40) ContentFrame.Size = UDim2.new(1, 0, 1, -40) local ToggleBtn = Instance.new("TextButton") ToggleBtn.Name = "ToggleBtn" ToggleBtn.Parent = ContentFrame ToggleBtn.BackgroundColor3 = Color3.fromRGB(46, 204, 113) ToggleBtn.Position = UDim2.new(0, 15, 0, 10) ToggleBtn.Size = UDim2.new(1, -30, 0, 40) ToggleBtn.Font = Enum.Font.GothamBold ToggleBtn.Text = "ENABLE FREECAM" ToggleBtn.TextColor3 = Color3.fromRGB(255, 255, 255) ToggleBtn.TextSize = 14 ToggleBtn.AutoButtonColor = false local ToggleCorner = Instance.new("UICorner") ToggleCorner.CornerRadius = UDim.new(0, 6) ToggleCorner.Parent = ToggleBtn local ToggleStroke = Instance.new("UIStroke") ToggleStroke.Parent = ToggleBtn ToggleStroke.Color = Color3.fromRGB(255,255,255) ToggleStroke.Transparency = 0.8 ToggleStroke.Thickness = 1 local SpeedLabel = Instance.new("TextLabel") SpeedLabel.Name = "SpeedLabel" SpeedLabel.Parent = ContentFrame SpeedLabel.BackgroundTransparency = 1 SpeedLabel.Position = UDim2.new(0, 15, 0, 60) SpeedLabel.Size = UDim2.new(0, 80, 0, 30) SpeedLabel.Font = Enum.Font.GothamMedium SpeedLabel.Text = "Speed:" SpeedLabel.TextColor3 = Color3.fromRGB(200, 200, 200) SpeedLabel.TextSize = 14 SpeedLabel.TextXAlignment = Enum.TextXAlignment.Left local SpeedInput = Instance.new("TextBox") SpeedInput.Name = "SpeedInput" SpeedInput.Parent = ContentFrame SpeedInput.BackgroundColor3 = Color3.fromRGB(45, 45, 50) SpeedInput.Position = UDim2.new(0, 70, 0, 60) SpeedInput.Size = UDim2.new(1, -85, 0, 30) SpeedInput.Font = Enum.Font.Gotham SpeedInput.Text = "64" SpeedInput.PlaceholderText = "Default: 64" SpeedInput.TextColor3 = Color3.fromRGB(255, 255, 255) SpeedInput.TextSize = 14 local SpeedCorner = Instance.new("UICorner") SpeedCorner.CornerRadius = UDim.new(0, 6) SpeedCorner.Parent = SpeedInput local function CreateToggleOption(name, text, yPos, defaultState, callback) local Label = Instance.new("TextLabel") Label.Name = name .. "Label" Label.Parent = ContentFrame Label.BackgroundTransparency = 1 Label.Position = UDim2.new(0, 15, 0, yPos) Label.Size = UDim2.new(0, 150, 0, 30) Label.Font = Enum.Font.GothamMedium Label.Text = text Label.TextColor3 = Color3.fromRGB(200, 200, 200) Label.TextSize = 14 Label.TextXAlignment = Enum.TextXAlignment.Left local Button = Instance.new("TextButton") Button.Name = name .. "Btn" Button.Parent = ContentFrame Button.BackgroundColor3 = defaultState and Color3.fromRGB(46, 204, 113) or Color3.fromRGB(70, 70, 75) Button.Position = UDim2.new(1, -45, 0, yPos) Button.Size = UDim2.new(0, 30, 0, 30) Button.Font = Enum.Font.GothamBold Button.Text = "" Button.AutoButtonColor = false local Corner = Instance.new("UICorner") Corner.CornerRadius = UDim.new(0, 6) Corner.Parent = Button Button:SetAttribute("Active", defaultState) Button.MouseButton1Click:Connect(function() local isActive = not Button:GetAttribute("Active") Button:SetAttribute("Active", isActive) TweenService:Create(Button, TweenInfo.new(0.2), {BackgroundColor3 = isActive and Color3.fromRGB(46, 204, 113) or Color3.fromRGB(70, 70, 75)}):Play() if callback then callback(isActive) end end) return Button end local freecamEnabled = false local CursorToggleBtn = CreateToggleOption("CursorToggle", "Show Cursor", 100, true, function(state) if freecamEnabled then UserInputService.MouseIconEnabled = state end end) local KeybindToggleBtn = CreateToggleOption("KeybindToggle", "Enable Keybind", 140, false) local KeybindLabel = Instance.new("TextLabel") KeybindLabel.Parent = ContentFrame KeybindLabel.BackgroundTransparency = 1 KeybindLabel.Position = UDim2.new(0, 15, 0, 180) KeybindLabel.Size = UDim2.new(0, 150, 0, 30) KeybindLabel.Font = Enum.Font.GothamMedium KeybindLabel.Text = "Keybind:" KeybindLabel.TextColor3 = Color3.fromRGB(200, 200, 200) KeybindLabel.TextSize = 14 KeybindLabel.TextXAlignment = Enum.TextXAlignment.Left local KeybindConfig = {Modifiers = {}, Key = nil} local KeybindButton = Instance.new("TextButton") KeybindButton.Parent = ContentFrame KeybindButton.BackgroundColor3 = Color3.fromRGB(45, 45, 50) KeybindButton.Position = UDim2.new(0, 80, 0, 180) KeybindButton.Size = UDim2.new(1, -95, 0, 30) KeybindButton.Font = Enum.Font.Gotham KeybindButton.Text = "None" KeybindButton.TextColor3 = Color3.fromRGB(255, 255, 255) KeybindButton.TextSize = 13 KeybindButton.AutoButtonColor = false local KeyCorner = Instance.new("UICorner") KeyCorner.CornerRadius = UDim.new(0, 6) KeyCorner.Parent = KeybindButton local isBinding = false KeybindButton.MouseButton1Click:Connect(function() if isBinding then return end isBinding = true KeybindButton.Text = "Press keys..." KeybindButton.TextColor3 = Color3.fromRGB(255, 200, 50) local heldMods = {} local inputConnection inputConnection = UserInputService.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then local key = input.KeyCode if key == Enum.KeyCode.LeftShift or key == Enum.KeyCode.RightShift then if not table.find(heldMods, "Shift") then table.insert(heldMods, "Shift") end return elseif key == Enum.KeyCode.LeftControl or key == Enum.KeyCode.RightControl then if not table.find(heldMods, "Ctrl") then table.insert(heldMods, "Ctrl") end return elseif key == Enum.KeyCode.LeftAlt or key == Enum.KeyCode.RightAlt then if not table.find(heldMods, "Alt") then table.insert(heldMods, "Alt") end return end KeybindConfig.Modifiers = {unpack(heldMods)} KeybindConfig.Key = key local text = "" for _, m in ipairs(KeybindConfig.Modifiers) do text = text .. m .. " + " end text = text .. key.Name KeybindButton.Text = text KeybindButton.TextColor3 = Color3.fromRGB(255, 255, 255) isBinding = false inputConnection:Disconnect() end end) end) local function animateHover(button, entering) local targetColor = button.Name == "CloseBtn" and (entering and Color3.fromRGB(230, 80, 80) or Color3.fromRGB(200, 60, 60)) or button.Name == "MinimizeBtn" and (entering and Color3.fromRGB(90, 90, 95) or Color3.fromRGB(70, 70, 75)) or (entering and button.BackgroundColor3:Lerp(Color3.new(1,1,1), 0.1) or button.BackgroundColor3) if button.Name == "ToggleBtn" then local baseColor = button:GetAttribute("BaseColor") or button.BackgroundColor3 if entering then targetColor = baseColor:Lerp(Color3.new(1,1,1), 0.1) else targetColor = baseColor end end TweenService:Create(button, TweenInfo.new(0.2), {BackgroundColor3 = targetColor}):Play() end for _, btn in pairs({CloseBtn, MinimizeBtn, ToggleBtn}) do btn.MouseEnter:Connect(function() animateHover(btn, true) end) btn.MouseLeave:Connect(function() animateHover(btn, false) end) if btn.Name == "ToggleBtn" then btn:SetAttribute("BaseColor", btn.BackgroundColor3) end end local dragging, dragInput, dragStart, startPos local function update(input) local delta = input.Position - dragStart local targetPos = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y) TweenService:Create(MainFrame, TweenInfo.new(0.05), {Position = targetPos}):Play() end local function makeDraggable(obj) obj.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then dragging = true dragStart = input.Position startPos = MainFrame.Position input.Changed:Connect(function() if input.UserInputState == Enum.UserInputState.End then dragging = false end end) end end) obj.InputChanged:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then dragInput = input end end) end makeDraggable(TitleBar) UserInputService.InputChanged:Connect(function(input) if input == dragInput and dragging then update(input) end end) local isMinimized = false local minDragStart = nil local minFrameStart = nil local isMinDragging = false MinimizeBtn.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then isMinDragging = false minDragStart = input.Position minFrameStart = MainFrame.Position local moveCon local endCon moveCon = UserInputService.InputChanged:Connect(function(moveInput) if moveInput.UserInputType == Enum.UserInputType.MouseMovement or moveInput.UserInputType == Enum.UserInputType.Touch then local delta = moveInput.Position - minDragStart if delta.Magnitude > 5 then isMinDragging = true if isMinimized then local targetPos = UDim2.new(minFrameStart.X.Scale, minFrameStart.X.Offset + delta.X, minFrameStart.Y.Scale, minFrameStart.Y.Offset + delta.Y) TweenService:Create(MainFrame, TweenInfo.new(0.05), {Position = targetPos}):Play() end end end end) endCon = input.Changed:Connect(function() if input.UserInputState == Enum.UserInputState.End then moveCon:Disconnect() endCon:Disconnect() if not isMinDragging then isMinimized = not isMinimized local targetSize = isMinimized and MINIMIZED_SIZE or EXPANDED_SIZE local targetText = isMinimized and "+" or "-" MinimizeBtn.Text = targetText TweenService:Create(MainFrame, ANIM_INFO, {Size = targetSize}):Play() if isMinimized then TitleText.Visible = false CloseBtn.Visible = false TitleCover.Visible = false TitleBar.BackgroundTransparency = 1 ButtonsContainer.Position = UDim2.new(0, 0, 0, 0) ButtonsContainer.Size = UDim2.new(1, 0, 1, 0) MinimizeBtn.Position = UDim2.new(0, 0, 0, 0) MinimizeBtn.Size = UDim2.new(1, 0, 1, 0) MainFrame.BackgroundTransparency = 1 MainStroke.Transparency = 1 else TitleText.Visible = true CloseBtn.Visible = true TitleCover.Visible = true TitleBar.BackgroundTransparency = 0 ButtonsContainer.Position = UDim2.new(1, -70, 0, 5) ButtonsContainer.Size = UDim2.new(0, 65, 0, 30) MinimizeBtn.Position = UDim2.new(1, -65, 0, 0) MinimizeBtn.Size = UDim2.new(0, 30, 0, 30) MainFrame.BackgroundTransparency = 0 MainStroke.Transparency = 0.5 end end end end) end end) local pi = math.pi local abs = math.abs local clamp = math.clamp local exp = math.exp local rad = math.rad local sign = math.sign local sqrt = math.sqrt local tan = math.tan local LocalPlayer = Players.LocalPlayer if not LocalPlayer then Players:GetPropertyChangedSignal("LocalPlayer"):Wait() LocalPlayer = Players.LocalPlayer end local Camera = Workspace.CurrentCamera Workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(function() local newCamera = Workspace.CurrentCamera if newCamera then Camera = newCamera end end) local INPUT_PRIORITY = Enum.ContextActionPriority.High.Value local BaseNavSpeed = 64 local NAV_GAIN = Vector3.new(1, 1, 1) * BaseNavSpeed local PAN_GAIN = Vector2.new(0.75, 1)*8 local FOV_GAIN = 300 local PITCH_LIMIT = rad(90) local VEL_STIFFNESS = 1.5 local PAN_STIFFNESS = 1.0 local FOV_STIFFNESS = 4.0 local Spring = {} do Spring.__index = Spring function Spring.new(freq, pos) local self = setmetatable({}, Spring) self.f = freq self.p = pos self.v = pos*0 return self end function Spring:Update(dt, goal) local f = self.f*2*pi local p0 = self.p local v0 = self.v local offset = goal - p0 local decay = exp(-f*dt) local p1 = goal + (v0*dt - offset*(f*dt + 1))*decay local v1 = (f*dt*(offset*f - v0) + v0)*decay self.p = p1 self.v = v1 return p1 end function Spring:Reset(pos) self.p = pos self.v = pos*0 end end local cameraPos = Vector3.new() local cameraRot = Vector2.new() local cameraFov = 0 local velSpring = Spring.new(VEL_STIFFNESS, Vector3.new()) local panSpring = Spring.new(PAN_STIFFNESS, Vector2.new()) local fovSpring = Spring.new(FOV_STIFFNESS, 0) local Input = {} do local thumbstickCurve do local K_CURVATURE = 2.0 local K_DEADZONE = 0.15 local function fCurve(x) return (exp(K_CURVATURE*x) - 1)/(exp(K_CURVATURE) - 1) end local function fDeadzone(x) return fCurve((x - K_DEADZONE)/(1 - K_DEADZONE)) end function thumbstickCurve(x) return sign(x)*clamp(fDeadzone(abs(x)), 0, 1) end end local gamepad = { ButtonX = 0, ButtonY = 0, DPadDown = 0, DPadUp = 0, ButtonL2 = 0, ButtonR2 = 0, Thumbstick1 = Vector2.new(), Thumbstick2 = Vector2.new(), } local keyboard = { W = 0, A = 0, S = 0, D = 0, E = 0, Q = 0, U = 0, H = 0, J = 0, K = 0, I = 0, Y = 0, Up = 0, Down = 0, LeftShift = 0, RightShift = 0, } local mouse = { Delta = Vector2.new(), MouseWheel = 0, } local NAV_GAMEPAD_SPEED = Vector3.new(1, 1, 1) local NAV_KEYBOARD_SPEED = Vector3.new(1, 1, 1) local PAN_MOUSE_SPEED = Vector2.new(1, 1)*(pi/64) local PAN_GAMEPAD_SPEED = Vector2.new(1, 1)*(pi/8) local FOV_WHEEL_SPEED = 1.0 local FOV_GAMEPAD_SPEED = 0.25 local NAV_ADJ_SPEED = 0.75 local NAV_SHIFT_MUL = 0.25 local navSpeed = 1 function Input.Vel(dt) navSpeed = clamp(navSpeed + dt*(keyboard.Up - keyboard.Down)*NAV_ADJ_SPEED, 0.01, 4) local kGamepad = Vector3.new( thumbstickCurve(gamepad.Thumbstick1.x), thumbstickCurve(gamepad.ButtonR2) - thumbstickCurve(gamepad.ButtonL2), thumbstickCurve(-gamepad.Thumbstick1.y) )*NAV_GAMEPAD_SPEED local kKeyboard = Vector3.new( keyboard.D - keyboard.A + keyboard.K - keyboard.H, keyboard.E - keyboard.Q + keyboard.I - keyboard.Y, keyboard.S - keyboard.W + keyboard.J - keyboard.U )*NAV_KEYBOARD_SPEED local shift = UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) or UserInputService:IsKeyDown(Enum.KeyCode.RightShift) return (kGamepad + kKeyboard)*(navSpeed*(shift and NAV_SHIFT_MUL or 1)) end function Input.Pan(dt) local kGamepad = Vector2.new( thumbstickCurve(gamepad.Thumbstick2.y), thumbstickCurve(-gamepad.Thumbstick2.x) )*PAN_GAMEPAD_SPEED local kMouse = mouse.Delta*PAN_MOUSE_SPEED mouse.Delta = Vector2.new() return kGamepad + kMouse end function Input.Fov(dt) local kGamepad = (gamepad.ButtonX - gamepad.ButtonY)*FOV_GAMEPAD_SPEED local kMouse = mouse.MouseWheel*FOV_WHEEL_SPEED mouse.MouseWheel = 0 return kGamepad + kMouse end do local function Keypress(action, state, input) keyboard[input.KeyCode.Name] = state == Enum.UserInputState.Begin and 1 or 0 return Enum.ContextActionResult.Sink end local function GpButton(action, state, input) gamepad[input.KeyCode.Name] = state == Enum.UserInputState.Begin and 1 or 0 return Enum.ContextActionResult.Sink end local function MousePan(action, state, input) local delta = input.Delta mouse.Delta = Vector2.new(-delta.y, -delta.x) return Enum.ContextActionResult.Sink end local function Thumb(action, state, input) gamepad[input.KeyCode.Name] = input.Position return Enum.ContextActionResult.Sink end local function Trigger(action, state, input) gamepad[input.KeyCode.Name] = input.Position.z return Enum.ContextActionResult.Sink end local function MouseWheel(action, state, input) mouse[input.UserInputType.Name] = -input.Position.z return Enum.ContextActionResult.Sink end local function Zero(t) for k, v in pairs(t) do t[k] = v*0 end end function Input.StartCapture() ContextActionService:BindActionAtPriority("FreecamKeyboard", Keypress, false, INPUT_PRIORITY, Enum.KeyCode.W, Enum.KeyCode.U, Enum.KeyCode.A, Enum.KeyCode.H, Enum.KeyCode.S, Enum.KeyCode.J, Enum.KeyCode.D, Enum.KeyCode.K, Enum.KeyCode.E, Enum.KeyCode.I, Enum.KeyCode.Q, Enum.KeyCode.Y, Enum.KeyCode.Up, Enum.KeyCode.Down ) ContextActionService:BindActionAtPriority("FreecamMousePan", MousePan, false, INPUT_PRIORITY, Enum.UserInputType.MouseMovement) ContextActionService:BindActionAtPriority("FreecamMouseWheel", MouseWheel, false, INPUT_PRIORITY, Enum.UserInputType.MouseWheel) ContextActionService:BindActionAtPriority("FreecamGamepadButton", GpButton, false, INPUT_PRIORITY, Enum.KeyCode.ButtonX, Enum.KeyCode.ButtonY) ContextActionService:BindActionAtPriority("FreecamGamepadTrigger", Trigger, false, INPUT_PRIORITY, Enum.KeyCode.ButtonR2, Enum.KeyCode.ButtonL2) ContextActionService:BindActionAtPriority("FreecamGamepadThumbstick", Thumb, false, INPUT_PRIORITY, Enum.KeyCode.Thumbstick1, Enum.KeyCode.Thumbstick2) end function Input.StopCapture() navSpeed = 1 Zero(gamepad) Zero(keyboard) Zero(mouse) ContextActionService:UnbindAction("FreecamKeyboard") ContextActionService:UnbindAction("FreecamMousePan") ContextActionService:UnbindAction("FreecamMouseWheel") ContextActionService:UnbindAction("FreecamGamepadButton") ContextActionService:UnbindAction("FreecamGamepadTrigger") ContextActionService:UnbindAction("FreecamGamepadThumbstick") end end end local function GetFocusDistance(cameraFrame) local znear = 0.1 local viewport = Camera.ViewportSize local projy = 2*tan(cameraFov/2) local projx = viewport.x/viewport.y*projy local fx = cameraFrame.rightVector local fy = cameraFrame.upVector local fz = cameraFrame.lookVector local minVect = Vector3.new() local minDist = 512 for x = 0, 1, 0.5 do for y = 0, 1, 0.5 do local cx = (x - 0.5)*projx local cy = (y - 0.5)*projy local offset = fx*cx - fy*cy + fz local origin = cameraFrame.p + offset*znear local part, hit = Workspace:FindPartOnRay(Ray.new(origin, offset.unit*minDist)) local dist = (hit - origin).magnitude if minDist > dist then minDist = dist minVect = offset.unit end end end return fz:Dot(minVect)*minDist end local function StepFreecam(dt) local vel = velSpring:Update(dt, Input.Vel(dt)) local pan = panSpring:Update(dt, Input.Pan(dt)) local fov = fovSpring:Update(dt, Input.Fov(dt)) local zoomFactor = sqrt(tan(rad(70/2))/tan(rad(cameraFov/2))) cameraFov = clamp(cameraFov + fov*FOV_GAIN*(dt/zoomFactor), 1, 120) cameraRot = cameraRot + pan*PAN_GAIN*(dt/zoomFactor) cameraRot = Vector2.new(clamp(cameraRot.x, -PITCH_LIMIT, PITCH_LIMIT), cameraRot.y%(2*pi)) local currentNavGain = Vector3.new(1, 1, 1) * BaseNavSpeed local cameraCFrame = CFrame.new(cameraPos)*CFrame.fromOrientation(cameraRot.x, cameraRot.y, 0)*CFrame.new(vel*currentNavGain*dt) cameraPos = cameraCFrame.p Camera.CFrame = cameraCFrame Camera.Focus = cameraCFrame*CFrame.new(0, 0, -GetFocusDistance(cameraCFrame)) Camera.FieldOfView = cameraFov end local PlayerState = {} do local mouseIconEnabled local cameraSubject local cameraType local cameraFocus local cameraCFrame local cameraFieldOfView local screenGuis = {} local coreGuis = { Backpack = true, Chat = true, Health = true, PlayerList = true, } local setCores = { BadgesNotificationsActive = true, PointsNotificationsActive = true, } function PlayerState.Push() for name in pairs(coreGuis) do pcall(function() coreGuis[name] = StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType[name]) StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[name], false) end) end for name in pairs(setCores) do pcall(function() setCores[name] = StarterGui:GetCore(name) StarterGui:SetCore(name, false) end) end local playergui = LocalPlayer:FindFirstChildOfClass("PlayerGui") if playergui then for _, gui in pairs(playergui:GetChildren()) do if gui:IsA("ScreenGui") and gui.Enabled and gui ~= ScreenGui then screenGuis[#screenGuis + 1] = gui gui.Enabled = false end end end cameraFieldOfView = Camera.FieldOfView Camera.FieldOfView = 70 cameraType = Camera.CameraType Camera.CameraType = Enum.CameraType.Custom cameraSubject = Camera.CameraSubject Camera.CameraSubject = nil cameraCFrame = Camera.CFrame cameraFocus = Camera.Focus mouseIconEnabled = UserInputService.MouseIconEnabled if CursorToggleBtn:GetAttribute("Active") then UserInputService.MouseIconEnabled = true else UserInputService.MouseIconEnabled = false end end function PlayerState.Pop() for name, isEnabled in pairs(coreGuis) do pcall(function() StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType[name], isEnabled) end) end for name, isEnabled in pairs(setCores) do pcall(function() StarterGui:SetCore(name, isEnabled) end) end for _, gui in pairs(screenGuis) do if gui.Parent then gui.Enabled = true end end Camera.FieldOfView = cameraFieldOfView cameraFieldOfView = nil Camera.CameraType = cameraType cameraType = nil Camera.CameraSubject = cameraSubject cameraSubject = nil Camera.CFrame = cameraCFrame cameraCFrame = nil Camera.Focus = cameraFocus cameraFocus = nil if mouseIconEnabled ~= nil then UserInputService.MouseIconEnabled = mouseIconEnabled end mouseIconEnabled = nil end end local function StartFreecam() local cameraCFrame = Camera.CFrame cameraRot = Vector2.new(cameraCFrame:toEulerAnglesYXZ()) cameraPos = cameraCFrame.p cameraFov = Camera.FieldOfView velSpring:Reset(Vector3.new()) panSpring:Reset(Vector2.new()) fovSpring:Reset(0) PlayerState.Push() RunService:BindToRenderStep("Freecam", Enum.RenderPriority.Camera.Value, StepFreecam) Input.StartCapture() end local function StopFreecam() Input.StopCapture() RunService:UnbindFromRenderStep("Freecam") PlayerState.Pop() end local function ToggleFreecam() if freecamEnabled then StopFreecam() ToggleBtn.Text = "ENABLE FREECAM" ToggleBtn.BackgroundColor3 = Color3.fromRGB(46, 204, 113) ToggleBtn:SetAttribute("BaseColor", Color3.fromRGB(46, 204, 113)) else StartFreecam() ToggleBtn.Text = "DISABLE FREECAM" ToggleBtn.BackgroundColor3 = Color3.fromRGB(231, 76, 60) ToggleBtn:SetAttribute("BaseColor", Color3.fromRGB(231, 76, 60)) end freecamEnabled = not freecamEnabled end ToggleBtn.MouseButton1Click:Connect(ToggleFreecam) SpeedInput.FocusLost:Connect(function() local val = tonumber(SpeedInput.Text) if val then BaseNavSpeed = val else SpeedInput.Text = tostring(BaseNavSpeed) end end) CloseBtn.MouseButton1Click:Connect(function() if freecamEnabled then StopFreecam() end ScreenGui:Destroy() end) UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if not KeybindToggleBtn:GetAttribute("Active") then return end if not KeybindConfig.Key then return end if input.KeyCode == KeybindConfig.Key then local modsCorrect = true for _, mod in ipairs(KeybindConfig.Modifiers) do local k1, k2 if mod == "Shift" then k1, k2 = Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift end if mod == "Ctrl" then k1, k2 = Enum.KeyCode.LeftControl, Enum.KeyCode.RightControl end if mod == "Alt" then k1, k2 = Enum.KeyCode.LeftAlt, Enum.KeyCode.RightAlt end if not (UserInputService:IsKeyDown(k1) or UserInputService:IsKeyDown(k2)) then modsCorrect = false break end end if modsCorrect then ToggleFreecam() end end end)