Advertisement
AnonymousJG179

Superman Fly

Jul 10th, 2024
2,377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. -- Flying like Superman Script
  2.  
  3. local player = game.Players.LocalPlayer
  4. local mouse = player:GetMouse()
  5. local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
  6. local flying = false
  7. local speed = 100
  8. local rotationSpeed = 10
  9. local speedChange = 50 -- Adjust the speed change rate
  10.  
  11. -- Screen width for determining mouse position
  12. local screenWidth = workspace.CurrentCamera.ViewportSize.X
  13.  
  14. -- Function to start flying
  15. local function startFlying()
  16. local bodyGyro = Instance.new("BodyGyro")
  17. local bodyVelocity = Instance.new("BodyVelocity")
  18.  
  19. bodyGyro.P = 9e4
  20. bodyGyro.D = 1e3
  21. bodyGyro.MaxTorque = Vector3.new(9e4, 9e4, 9e4)
  22. bodyGyro.Parent = humanoidRootPart
  23.  
  24. bodyVelocity.Velocity = Vector3.new(0, 0, 0)
  25. bodyVelocity.MaxForce = Vector3.new(9e4, 9e4, 9e4)
  26. bodyVelocity.Parent = humanoidRootPart
  27.  
  28. flying = true
  29.  
  30. -- Initial horizontal orientation facing downward
  31. bodyGyro.CFrame = humanoidRootPart.CFrame * CFrame.Angles(math.rad(-90), 0, 0)
  32.  
  33. -- Fly towards mouse direction
  34. while flying do
  35. local direction = (mouse.Hit.p - humanoidRootPart.Position).unit
  36.  
  37. -- Determine rotation based on mouse position
  38. local mouseX = mouse.X
  39. local rotationAngle = 0
  40. if mouseX < screenWidth * 0.33 then
  41. rotationAngle = rotationSpeed -- Rotate left
  42. elseif mouseX > screenWidth * 0.66 then
  43. rotationAngle = -rotationSpeed -- Rotate right
  44. end
  45.  
  46. -- Maintain horizontal orientation with rotation control
  47. bodyGyro.CFrame = CFrame.new(humanoidRootPart.Position, mouse.Hit.p) * CFrame.Angles(math.rad(-90), 0, 0) * CFrame.Angles(0, math.rad(rotationAngle), 0)
  48. bodyVelocity.Velocity = direction * speed
  49. wait()
  50. end
  51.  
  52. -- Cleanup
  53. bodyGyro:Destroy()
  54. bodyVelocity:Destroy()
  55. end
  56.  
  57. -- Function to stop flying
  58. local function stopFlying()
  59. flying = false
  60. end
  61.  
  62. -- Key press listener
  63. mouse.KeyDown:Connect(function(key)
  64. if key == "f" then
  65. if not flying then
  66. startFlying()
  67. else
  68. stopFlying()
  69. end
  70. elseif key == "e" then
  71. speed = speed + speedChange -- Accelerate faster
  72. elseif key == "q" then
  73. speed = speed - speedChange -- Decelerate faster
  74. if speed < 0 then speed = 0 end -- Ensure speed doesn't go negative
  75. end
  76. end)
  77.  
  78. -- Key release listener
  79. mouse.KeyUp:Connect(function(key)
  80. -- No action needed for key release in this context
  81. end)
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement