Advertisement
Cra-Z-Gaming

Boost Forward W/Spacebar

Dec 22nd, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | Gaming | 0 0
  1. --boost forward w/spacebar, script--
  2.  
  3. local player = game.Players.LocalPlayer
  4. local character = player.Character or player.CharacterAdded:Wait()
  5. local humanoid = character:WaitForChild("Humanoid")
  6. local rootPart = character:WaitForChild("HumanoidRootPart")
  7.  
  8. local userInputService = game:GetService("UserInputService")
  9. local runService = game:GetService("RunService")
  10.  
  11. local flying = false
  12. local flySpeed = 50
  13.  
  14. -- Create BodyVelocity to control movement
  15. local bodyVelocity = Instance.new("BodyVelocity")
  16. bodyVelocity.MaxForce = Vector3.new(1e6, 1e6, 1e6) -- Allow strong forces
  17. bodyVelocity.P = 10000 -- Powerful force to counteract gravity
  18.  
  19. -- Create BodyGyro to lock orientation smoothly
  20. local bodyGyro = Instance.new("BodyGyro")
  21. bodyGyro.MaxTorque = Vector3.new(1e6, 1e6, 1e6) -- Allow strong torque in all directions
  22. bodyGyro.P = 5000 -- Higher stabilization power for faster response
  23. bodyGyro.D = 150 -- Damping to smooth out rotation transitions
  24.  
  25. -- Disable falling animation by preventing unwanted state changes
  26. local function disableFallingAnimation()
  27. humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false) -- Prevent falling state
  28. humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false) -- Prevent ragdoll physics
  29. end
  30.  
  31. -- Enable all default animations and states after flying
  32. local function enableNormalAnimations()
  33. humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
  34. humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
  35. end
  36.  
  37. -- Update movement and orientation continuously
  38. local function updateFlight()
  39. if flying then
  40. -- Update velocity to move forward
  41. bodyVelocity.Velocity = rootPart.CFrame.LookVector * flySpeed
  42.  
  43. -- Smoothly rotate to face forward
  44. bodyGyro.CFrame = rootPart.CFrame
  45. end
  46. end
  47.  
  48. local function onInputBegan(input, gameProcessed)
  49. if gameProcessed then return end
  50. if input.KeyCode == Enum.KeyCode.Space and not flying then
  51. flying = true
  52.  
  53. -- Attach BodyVelocity and BodyGyro to the root part
  54. bodyVelocity.Parent = rootPart
  55. bodyGyro.Parent = rootPart
  56.  
  57. disableFallingAnimation() -- Stop falling animation
  58.  
  59. -- Start updating flight
  60. runService.RenderStepped:Connect(updateFlight)
  61. end
  62. end
  63.  
  64. local function onInputEnded(input, gameProcessed)
  65. if input.KeyCode == Enum.KeyCode.Space and flying then
  66. flying = false
  67.  
  68. -- Remove BodyVelocity and BodyGyro
  69. bodyVelocity.Parent = nil
  70. bodyGyro.Parent = nil
  71.  
  72. enableNormalAnimations() -- Restore animations
  73. end
  74. end
  75.  
  76. -- Enable jumping while flying
  77. local function onJumpRequest()
  78. if flying then
  79. humanoid:ChangeState(Enum.HumanoidStateType.Jumping) -- Force jump state
  80. end
  81. end
  82.  
  83. userInputService.InputBegan:Connect(onInputBegan)
  84. userInputService.InputEnded:Connect(onInputEnded)
  85. humanoid:GetPropertyChangedSignal("Jump"):Connect(onJumpRequest)
  86.  
Tags: boost "fly"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement