DrawingJhon

Adonis fly

Aug 2nd, 2020 (edited)
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.81 KB | None | 0 0
  1. local ls = NLS([==[
  2. local part = script.Parent
  3. local players = game:GetService("Players")
  4. local inputService = game:GetService("UserInputService")
  5. local runService = game:GetService("RunService")
  6. local contextService = game:GetService("ContextActionService")
  7. local player = players.LocalPlayer
  8. local char = player.Character
  9. local human = char:FindFirstChildOfClass("Humanoid")
  10. local aliveVal = part:WaitForChild("ADONIS_FLIGHT_ALIVE")
  11. local speed = script:WaitForChild("Speed").Value
  12. local noclip = script:WaitForChild("Noclip")
  13. local Create = Instance.new
  14. local flying = true
  15. local keyTab = {}
  16. local dir = {}
  17. local conn -- used for noclip
  18. local bPos, bGyro, antiLoop, humChanged
  19.  
  20. function Check()
  21.     if aliveVal.Parent == part and script.Parent == part then
  22.         return true
  23.     end
  24. end
  25.  
  26. function getCF(part, isFor)
  27.     local cframe = part.CFrame
  28.     local noRot = CFrame.new(cframe.p)
  29.     local x, y, z = (workspace.CurrentCamera.CoordinateFrame - workspace.CurrentCamera.CoordinateFrame.p):toEulerAnglesXYZ()
  30.     return noRot * CFrame.Angles(isFor and z or x, y, z)
  31. end
  32.  
  33. function dirToCom(part, mdir)
  34.     local dirs = {
  35.         Forward = ((getCF(part, true)*CFrame.new(0, 0, -1)) - part.CFrame.p).p;
  36.         Backward = ((getCF(part, true)*CFrame.new(0, 0, 1)) - part.CFrame.p).p;
  37.         Right = ((getCF(part)*CFrame.new(1, 0, 0)) - part.CFrame.p).p;
  38.         Left = ((getCF(part)*CFrame.new(-1, 0, 0)) - part.CFrame.p).p;
  39.     }
  40.    
  41.     for i,v in next,dirs do
  42.         if (v - mdir).magnitude <= 1.05 and mdir ~= Vector3.new(0,0,0) then
  43.             dir[i] = true
  44.         elseif not keyTab[i] then
  45.             dir[i] = false
  46.         end
  47.     end
  48. end
  49.  
  50. function Start()
  51.     local curSpeed = 0
  52.     local speedInc = speed/25
  53.     local camera = workspace.CurrentCamera
  54.     local antiReLoop = {}
  55.     local realPos = part.CFrame
  56.    
  57.     bPos, bGyro = Create("BodyPosition"), Create("BodyGyro")
  58.    
  59.     bPos.Parent = part
  60.     bPos.maxForce = Vector3.new(math.huge, math.huge, math.huge)
  61.     bPos.position = part.Position
  62.  
  63.     bGyro.Parent = part
  64.     bGyro.maxTorque = Vector3.new(9e9, 9e9, 9e9)
  65.     bGyro.cframe = part.CFrame
  66.    
  67.     antiLoop = antiReLoop
  68.    
  69.     if noclip.Value then
  70.         conn = runService.Stepped:Connect(function()
  71.             for _,v in pairs(char:GetDescendants()) do
  72.                 if v:IsA("BasePart") then
  73.                     v.CanCollide = false
  74.                 end
  75.             end
  76.         end)
  77.     end
  78.    
  79.     while flying and antiLoop == antiReLoop and Check() do
  80.         local new = bGyro.cframe - bGyro.cframe.p + bPos.position
  81.         if not dir.Forward and not dir.Backward and not dir.Up and not dir.Down and not dir.Left and not dir.Right then
  82.             curSpeed = 1
  83.         else
  84.             if dir.Up then
  85.                 new = new * CFrame.new(0, curSpeed, 0)
  86.                 curSpeed = curSpeed + speedInc
  87.             end
  88.            
  89.             if dir.Down then
  90.                 new = new * CFrame.new(0, -curSpeed, 0)
  91.                 curSpeed = curSpeed + speedInc
  92.             end
  93.            
  94.             if dir.Forward then
  95.                 new = new + camera.CoordinateFrame.lookVector * curSpeed
  96.                 curSpeed = curSpeed + speedInc
  97.             end
  98.            
  99.             if dir.Backward then
  100.                 new = new - camera.CoordinateFrame.lookVector * curSpeed
  101.                 curSpeed = curSpeed + speedInc
  102.             end
  103.            
  104.             if dir.Left then
  105.                 new = new * CFrame.new(-curSpeed, 0, 0)
  106.                 curSpeed = curSpeed + speedInc
  107.             end
  108.            
  109.             if dir.Right then
  110.                 new = new * CFrame.new(curSpeed, 0, 0)
  111.                 curSpeed = curSpeed + speedInc
  112.             end
  113.        
  114.             if curSpeed > speed then
  115.                 curSpeed = speed
  116.             end
  117.         end
  118.        
  119.         human.PlatformStand = true
  120.         bPos.position = new.p
  121.    
  122.         if dir.Forward then
  123.             bGyro.cframe = camera.CoordinateFrame*CFrame.Angles(-math.rad(curSpeed*7.5), 0, 0)
  124.         elseif dir.Backward then
  125.             bGyro.cframe = camera.CoordinateFrame*CFrame.Angles(math.rad(curSpeed*7.5), 0, 0)
  126.         else
  127.             bGyro.cframe = camera.CoordinateFrame
  128.         end
  129.        
  130.         runService.RenderStepped:Wait()
  131.     end
  132.    
  133.     Stop()
  134. end
  135.  
  136. function Stop()
  137.     flying = false
  138.     human.PlatformStand = false
  139.    
  140.     if humChanged then
  141.         humChanged:Disconnect()
  142.     end
  143.    
  144.     if bPos then
  145.         bPos:Destroy()
  146.     end
  147.    
  148.     if bGyro then
  149.         bGyro:Destroy()
  150.     end
  151.    
  152.     if conn then
  153.         conn:Disconnect()
  154.     end
  155. end
  156.  
  157. local debounce = false
  158. function Toggle()
  159.     if not debounce then
  160.         debounce = true
  161.         if not flying then
  162.             flying = true
  163.             coroutine.wrap(Start)()
  164.         else
  165.             flying = false
  166.             Stop()
  167.         end
  168.         wait(0.5)
  169.         debounce = false
  170.     end
  171. end
  172.  
  173. local function HandleInput(input, isGame, bool)
  174.     if not isGame then
  175.         if input.UserInputType == Enum.UserInputType.Keyboard then
  176.             if input.KeyCode == Enum.KeyCode.W then
  177.                 keyTab.Forward = bool
  178.                 dir.Forward = bool
  179.             elseif input.KeyCode == Enum.KeyCode.A then
  180.                 keyTab.Left = bool
  181.                 dir.Left = bool
  182.             elseif input.KeyCode == Enum.KeyCode.S then
  183.                 keyTab.Backward = bool
  184.                 dir.Backward = bool
  185.             elseif input.KeyCode == Enum.KeyCode.D then
  186.                 keyTab.Right = bool
  187.                 dir.Right = bool
  188.             elseif input.KeyCode == Enum.KeyCode.Q then
  189.                 keyTab.Down = bool
  190.                 dir.Down = bool
  191.             elseif input.KeyCode == Enum.KeyCode.Space then
  192.                 keyTab.Up = bool
  193.                 dir.Up = bool
  194.             elseif input.KeyCode == Enum.KeyCode.E and bool == true then
  195.                 Toggle()
  196.             end
  197.         end
  198.     end
  199. end
  200.  
  201. inputService.InputBegan:Connect(function(input, isGame)
  202.     HandleInput(input, isGame, true)
  203. end)
  204.  
  205. inputService.InputEnded:Connect(function(input, isGame)
  206.     HandleInput(input, isGame, false)
  207. end)
  208.    
  209. coroutine.wrap(Start)()
  210.  
  211. if not inputService.KeyboardEnabled then
  212.     human.Changed:connect(function()
  213.         dirToCom(part, human.MoveDirection)
  214.     end)
  215.    
  216.     contextService:BindAction("Toggle Flight", Toggle, true)
  217.     while Check() and wait(0.05) do end
  218.     contextService:UnbindAction("Toggle Flight")
  219.     script:Destroy()
  220. end
  221. ]==], owner.Character.HumanoidRootPart)
  222. local rootPart = owner.Character.HumanoidRootPart
  223. local p = Instance.new("BoolValue", rootPart)
  224. p.Name = "ADONIS_FLIGHT_ALIVE"
  225. p.Value = false
  226. local speed = Instance.new("NumberValue", ls)
  227. speed.Name = "Speed"
  228. speed.Value = 2
  229. local noclip = Instance.new("BoolValue", ls)
  230. noclip.Name = "Noclip"
  231. noclip.Value = false
Add Comment
Please, Sign In to add comment