Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Flying like Superman Script
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
- local flying = false
- local speed = 100
- local rotationSpeed = 10
- local speedChange = 50 -- Adjust the speed change rate
- -- Screen width for determining mouse position
- local screenWidth = workspace.CurrentCamera.ViewportSize.X
- -- Function to start flying
- local function startFlying()
- local bodyGyro = Instance.new("BodyGyro")
- local bodyVelocity = Instance.new("BodyVelocity")
- bodyGyro.P = 9e4
- bodyGyro.D = 1e3
- bodyGyro.MaxTorque = Vector3.new(9e4, 9e4, 9e4)
- bodyGyro.Parent = humanoidRootPart
- bodyVelocity.Velocity = Vector3.new(0, 0, 0)
- bodyVelocity.MaxForce = Vector3.new(9e4, 9e4, 9e4)
- bodyVelocity.Parent = humanoidRootPart
- flying = true
- -- Initial horizontal orientation facing downward
- bodyGyro.CFrame = humanoidRootPart.CFrame * CFrame.Angles(math.rad(-90), 0, 0)
- -- Fly towards mouse direction
- while flying do
- local direction = (mouse.Hit.p - humanoidRootPart.Position).unit
- -- Determine rotation based on mouse position
- local mouseX = mouse.X
- local rotationAngle = 0
- if mouseX < screenWidth * 0.33 then
- rotationAngle = rotationSpeed -- Rotate left
- elseif mouseX > screenWidth * 0.66 then
- rotationAngle = -rotationSpeed -- Rotate right
- end
- -- Maintain horizontal orientation with rotation control
- bodyGyro.CFrame = CFrame.new(humanoidRootPart.Position, mouse.Hit.p) * CFrame.Angles(math.rad(-90), 0, 0) * CFrame.Angles(0, math.rad(rotationAngle), 0)
- bodyVelocity.Velocity = direction * speed
- wait()
- end
- -- Cleanup
- bodyGyro:Destroy()
- bodyVelocity:Destroy()
- end
- -- Function to stop flying
- local function stopFlying()
- flying = false
- end
- -- Key press listener
- mouse.KeyDown:Connect(function(key)
- if key == "f" then
- if not flying then
- startFlying()
- else
- stopFlying()
- end
- elseif key == "e" then
- speed = speed + speedChange -- Accelerate faster
- elseif key == "q" then
- speed = speed - speedChange -- Decelerate faster
- if speed < 0 then speed = 0 end -- Ensure speed doesn't go negative
- end
- end)
- -- Key release listener
- mouse.KeyUp:Connect(function(key)
- -- No action needed for key release in this context
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement