Advertisement
Eproq012

5pto394o2k

Oct 3rd, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. -- Create the Tool
  2. local tool = Instance.new("Tool")
  3. tool.Name = "FlyTool"
  4. tool.RequiresHandle = false
  5. tool.Parent = game.Players.LocalPlayer.Backpack
  6.  
  7. local player = game.Players.LocalPlayer
  8. local character = player.Character or player.CharacterAdded:Wait()
  9. local humanoid = character:WaitForChild("Humanoid")
  10. local rootPart = character:WaitForChild("HumanoidRootPart")
  11. local animator = humanoid:FindFirstChild("Animator") or humanoid:WaitForChild("Animator")
  12.  
  13. -- Animations (front and jump animation)
  14. local flyForwardAnim = Instance.new("Animation")
  15. flyForwardAnim.AnimationId = "rbxassetid://17124063826"
  16.  
  17. local jumpAnim = Instance.new("Animation")
  18. jumpAnim.AnimationId = "rbxassetid://18893417968" -- Replaced with the finalized jump animation ID
  19.  
  20. -- Load animation tracks
  21. local flyForwardTrack = animator:LoadAnimation(flyForwardAnim)
  22. local jumpTrack = animator:LoadAnimation(jumpAnim)
  23.  
  24. -- Variables for flight and movement
  25. local flying = false
  26. local speed = 100
  27. local flightForce = Instance.new("BodyVelocity")
  28. local bodyGyro = Instance.new("BodyGyro")
  29. flightForce.MaxForce = Vector3.new(4000, 4000, 4000)
  30. flightForce.Velocity = Vector3.new(0, 0, 0)
  31. bodyGyro.MaxTorque = Vector3.new(4000, 4000, 4000)
  32. bodyGyro.CFrame = rootPart.CFrame
  33.  
  34. -- Input Setup
  35. local UIS = game:GetService("UserInputService")
  36. local camera = workspace.CurrentCamera
  37. local moveDirection = Vector3.new(0, 0, 0)
  38.  
  39. -- Function to start flying
  40. local function startFlying()
  41. flying = true
  42. flightForce.Parent = rootPart
  43. bodyGyro.Parent = rootPart
  44. humanoid.PlatformStand = true -- Disable default humanoid control
  45. end
  46.  
  47. -- Function to stop flying
  48. local function stopFlying()
  49. flying = false
  50. flightForce.Parent = nil
  51. bodyGyro.Parent = nil
  52. humanoid.PlatformStand = false
  53.  
  54. -- Stop the forward animation
  55. flyForwardTrack:Stop()
  56. end
  57.  
  58. -- Tool Activated and Deactivated
  59. tool.Activated:Connect(function()
  60. if flying then
  61. stopFlying()
  62. else
  63. startFlying()
  64. end
  65. end)
  66.  
  67. -- Handle Movement Inputs for W and Mobile (only forward movement)
  68. UIS.InputBegan:Connect(function(input)
  69. if flying then
  70. if input.KeyCode == Enum.KeyCode.W or input.UserInputType == Enum.UserInputType.Touch then
  71. moveDirection = Vector3.new(0, 0, -1) -- Move forward
  72. if not flyForwardTrack.IsPlaying then
  73. flyForwardTrack:Play() -- Play forward animation
  74. end
  75. end
  76. end
  77. end)
  78.  
  79. UIS.InputEnded:Connect(function(input)
  80. if flying then
  81. if input.KeyCode == Enum.KeyCode.W or input.UserInputType == Enum.UserInputType.Touch then
  82. flyForwardTrack:Stop() -- Stop forward animation
  83. end
  84. end
  85. end)
  86.  
  87. -- Jumping handler
  88. humanoid.Jumping:Connect(function(isJumping)
  89. if flying then
  90. humanoid.Jump = false -- Disable jumping while flying
  91. else
  92. if isJumping and not jumpTrack.IsPlaying then
  93. jumpTrack:Play() -- Play jump animation when jumping
  94. end
  95. end
  96. end)
  97.  
  98. -- Stop the jump animation when landing
  99. humanoid.StateChanged:Connect(function(oldState, newState)
  100. if newState == Enum.HumanoidStateType.Landed then
  101. jumpTrack:Stop()
  102. end
  103. end)
  104.  
  105. -- Flight control and body alignment
  106. game:GetService("RunService").Heartbeat:Connect(function()
  107. if flying then
  108. -- Set flying velocity and direction based on camera orientation
  109. local camForward = camera.CFrame.LookVector
  110. flightForce.Velocity = camForward * speed -- Always move forward
  111.  
  112. -- Adjust body tilt based on movement (Goku-style flight)
  113. local tiltAngle = math.rad(-90)
  114. bodyGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + camForward) * CFrame.Angles(tiltAngle, 0, 0)
  115. end
  116. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement