Advertisement
Delros12

Fly

Jan 1st, 2019 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. local settings = {
  2. speed = 2,
  3. acceleration = 0.5;
  4. }
  5.  
  6. local mouse = game.Players.LocalPlayer:GetMouse()
  7. local camera = workspace.Camera
  8.  
  9. local RS = game:GetService("RunService").RenderStepped
  10.  
  11. local player = game.Players.LocalPlayer
  12.  
  13. local pressedKeys = {}
  14. local touchedParts = {}
  15.  
  16. local flying = false
  17. function connectTouchEvent(part)
  18. if part:FindFirstChild("HasTouchEvent") == nil then
  19. part.Touched:connect(function(partTouched)
  20. if partTouched.CanCollide == true and flying == true then
  21. table.insert(touchedParts, partTouched)
  22. partTouched.CanCollide = false
  23. end
  24. end)
  25. Instance.new("BoolValue", part).Name = "HasTouchEvent"
  26. end
  27. end
  28.  
  29. local speedModifier = 1
  30. local acceleration = 0.008
  31.  
  32. local currentPos = Vector3.new(0, 0, 0)
  33.  
  34. local bodyForcePosition = nil
  35. mouse.KeyDown:connect(function(key)
  36. local char = player.Character
  37. if char then
  38. local head = char:FindFirstChild("Head")
  39.  
  40. pressedKeys[string.lower(tostring(key))] = string.lower(tostring(key))
  41. if string.lower(tostring(key)) == "f" and head then
  42. if flying == true then
  43. flying = false
  44. for _,c in pairs(char:GetChildren()) do
  45. if c.ClassName == "Part" then
  46. c.RotVelocity = Vector3.new(0, 0, 0)
  47. c.Velocity = Vector3.new(0, 0, 0)
  48.  
  49. c.CustomPhysicalProperties = PhysicalProperties.new(Enum.Material.Plastic)
  50. end
  51. end
  52. if bodyForcePosition then
  53. bodyForcePosition.Parent = nil
  54. end
  55. for _,part in pairs(touchedParts) do
  56. part.CanCollide = true
  57. end
  58. touchedParts = {}
  59. elseif flying == false then
  60. currentPos = head.Position
  61. if bodyForcePosition then
  62. bodyForcePosition.Parent = head
  63. end
  64. flying = true
  65. for _,c in pairs(char:GetChildren()) do
  66. if c.ClassName == "Part" then
  67. connectTouchEvent(c)
  68. c.CustomPhysicalProperties = PhysicalProperties.new(100, 2, 0)
  69. end
  70. end
  71. end
  72. end
  73. end
  74. end)
  75.  
  76. mouse.KeyUp:connect(function(key)
  77. pressedKeys[string.lower(tostring(key))] = nil
  78. end)
  79.  
  80. local char = nil
  81. local head = nil
  82.  
  83. local cameraLookVector = camera.CFrame.LookVector
  84. local cameraRightVector = camera.CFrame.RightVector
  85. local cameraUpVector = camera.CFrame.UpVector
  86.  
  87. local pressingKey = false
  88. RS:connect(function()
  89. char = player.Character
  90. if char then
  91. head = char:FindFirstChild("Head")
  92. if flying and head then
  93. cameraLookVector = camera.CFrame.LookVector
  94. cameraRightVector = camera.CFrame.RightVector
  95. cameraUpVector = camera.CFrame.UpVector
  96.  
  97. pressingKey = false
  98. for _,pressedKey in pairs(pressedKeys) do
  99. if string.lower(tostring(pressedKey)) == "w" then
  100. currentPos = currentPos + cameraLookVector*speedModifier
  101. pressingKey = true
  102. elseif string.lower(tostring(pressedKey)) == "s" then
  103. currentPos = currentPos + cameraLookVector*-speedModifier
  104. pressingKey = true
  105. elseif string.lower(tostring(pressedKey)) == "a" then
  106. currentPos = currentPos + cameraRightVector*-speedModifier
  107. pressingKey = true
  108. elseif string.lower(tostring(pressedKey)) == "d" then
  109. currentPos = currentPos + cameraRightVector*speedModifier
  110. pressingKey = true
  111. elseif string.lower(tostring(pressedKey)) == "e" then
  112. --currentPos = currentPos + cameraUpVector*speedModifier
  113. --pressingKey = true
  114. elseif string.lower(tostring(pressedKey)) == "q" then
  115. --currentPos = currentPos + cameraUpVector*-speedModifier
  116. --pressingKey = true
  117. end
  118. end
  119.  
  120. bodyForcePosition = head:FindFirstChild("FlyForce") or Instance.new("BodyPosition", head)
  121. bodyForcePosition.Position = currentPos
  122. bodyForcePosition.Name = "FlyForce"
  123. bodyForcePosition.P = 100000
  124. bodyForcePosition.D = 500
  125. bodyForcePosition.MaxForce = Vector3.new(4000000000, 4000000000, 4000000000)
  126.  
  127. if pressingKey then
  128. speedModifier = speedModifier + settings.acceleration
  129. else
  130. speedModifier = settings.speed
  131. end
  132. end
  133. end
  134. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement