Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local flySpeed = 2
- local uis = game:GetService("UserInputService")
- local player = game.Players.LocalPlayer
- local camera = workspace.CurrentCamera
- local flying = false
- local moveDirection = Vector3.zero
- local keysDown = {
- W = false,
- A = false,
- S = false,
- D = false,
- Space = false,
- LeftShift = false
- }
- -- Toggle flight
- local function toggleFlight()
- flying = not flying
- local char = player.Character
- if char and char:FindFirstChild("Humanoid") then
- char.Humanoid.PlatformStand = flying
- end
- end
- -- Input handlers
- uis.InputBegan:Connect(function(input, processed)
- if processed then return end
- if input.UserInputType == Enum.UserInputType.Keyboard then
- local key = input.KeyCode.Name
- -- Handle toggle
- if key == "T" then
- toggleFlight()
- end
- if keysDown[key] ~= nil then
- keysDown[key] = true
- end
- end
- end)
- uis.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.Keyboard then
- local key = input.KeyCode.Name
- if keysDown[key] ~= nil then
- keysDown[key] = false
- end
- end
- end)
- -- Flight loop
- game:GetService("RunService").RenderStepped:Connect(function()
- if not flying then return end
- local char = player.Character
- if not char or not char:FindFirstChild("HumanoidRootPart") then return end
- local rootPart = char.HumanoidRootPart
- -- Prevent falling
- rootPart.Velocity = Vector3.zero
- -- Get camera directions
- local camCF = camera.CFrame
- local forward = camCF.LookVector
- local right = camCF.RightVector
- local up = Vector3.new(0, 1, 0)
- -- Calculate movement
- moveDirection = Vector3.zero
- if keysDown.W then moveDirection += forward end
- if keysDown.S then moveDirection -= forward end
- if keysDown.A then moveDirection -= right end
- if keysDown.D then moveDirection += right end
- if keysDown.Space then moveDirection += up end
- if keysDown.LeftShift then moveDirection -= up end
- if moveDirection.Magnitude > 0 then
- moveDirection = moveDirection.Unit
- local newPos = rootPart.Position + moveDirection * flySpeed
- rootPart.CFrame = CFrame.new(newPos, newPos + camCF.LookVector)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement