Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Services
- local UIS = game:GetService("UserInputService")
- local RS = game:GetService("RunService")
- local TS = game:GetService("TweenService")
- -- Player & Character references
- local player = game.Players.LocalPlayer
- local char = player.Character or player.CharacterAdded:Wait()
- local root = char:WaitForChild("HumanoidRootPart")
- local camera = workspace.CurrentCamera
- local humanoid = char:WaitForChild("Humanoid")
- local controlModule = require(player.PlayerScripts.PlayerModule.ControlModule)
- -- Constantes
- local FLY_SPEED = 80
- -- Flying state
- local LocalFlying = false
- -- Input flags
- local ctrl = false
- local spaceKey = false
- local flyKey = Enum.KeyCode.F
- -- Name constants for created instances
- local LvName = "flyLinearVelocity"
- local AoName = "flyAlignOrientation"
- -- Zoom helper (opcional)
- local function Zoom(targetFOV, duration, repeatCount)
- local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, repeatCount, false, 0)
- local tween = TS:Create(camera, tweenInfo, { FieldOfView = targetFOV })
- tween:Play()
- end
- -- Start flying
- local function startFlying()
- if LocalFlying then return end
- local LV = Instance.new("LinearVelocity", root)
- local AO = Instance.new("AlignOrientation", root)
- LV.MaxForce = math.huge
- AO.MaxTorque = math.huge
- AO.Mode = Enum.OrientationAlignmentMode.OneAttachment
- LV.Attachment0 = root.RootAttachment
- AO.Attachment0 = root.RootAttachment
- LV.Name = LvName
- AO.Name = AoName
- humanoid.PlatformStand = true
- LocalFlying = true
- end
- -- Stop flying
- local function stopFlying()
- if not LocalFlying then return end
- local LV = root:FindFirstChild(LvName)
- local AO = root:FindFirstChild(AoName)
- humanoid.PlatformStand = false
- LocalFlying = false
- if LV then LV:Destroy() end
- if AO then AO:Destroy() end
- Zoom(70, 0.3, 0)
- end
- -- Input began
- UIS.InputBegan:Connect(function(input, gameProcessed)
- if gameProcessed then return end
- if input.KeyCode == flyKey then
- if not LocalFlying then
- startFlying()
- else
- stopFlying()
- end
- end
- if input.KeyCode == Enum.KeyCode.Space and LocalFlying then
- spaceKey = true
- end
- if input.KeyCode == Enum.KeyCode.LeftControl and LocalFlying then
- ctrl = true
- end
- end)
- -- Input ended
- UIS.InputEnded:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.Space then
- spaceKey = false
- end
- if input.KeyCode == Enum.KeyCode.LeftControl then
- ctrl = false
- end
- end)
- -- Main flight loop
- RS.Heartbeat:Connect(function()
- if LocalFlying then
- local LV = root:FindFirstChild(LvName)
- local AO = root:FindFirstChild(AoName)
- if not LV or not AO then return end
- local moveVector = controlModule:GetMoveVector()
- local direction = camera.CFrame:VectorToWorldSpace(moveVector)
- if moveVector.Magnitude ~= 0 then
- TS:Create(LV, TweenInfo.new(0.3), { VectorVelocity = direction * FLY_SPEED }):Play()
- else
- TS:Create(LV, TweenInfo.new(0.3), { VectorVelocity = Vector3.new(0, 0, 0) }):Play()
- Zoom(70, 0.3, 0)
- end
- if spaceKey then
- LV.VectorVelocity = LV.VectorVelocity + Vector3.new(0, FLY_SPEED / 15, 0)
- elseif ctrl then
- LV.VectorVelocity = LV.VectorVelocity - Vector3.new(0, FLY_SPEED / 15, 0)
- end
- if moveVector.Magnitude > 0 then
- --AO.CFrame = CFrame.new(root.Position, root.Position + direction)
- AO.RigidityEnabled = true
- AO.Responsiveness = 50
- else
- AO.CFrame = camera.CFrame
- AO.RigidityEnabled = false
- AO.Responsiveness = 10
- end
- AO.CFrame = camera.CFrame
- end
- end)
- -- Cleanup
- player.CharacterRemoving:Connect(function()
- stopFlying()
- end)
- script.Parent.AncestryChanged:Connect(function(_, parent)
- if not parent then
- stopFlying()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment