Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --boost forward w/spacebar, script--
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local rootPart = character:WaitForChild("HumanoidRootPart")
- local userInputService = game:GetService("UserInputService")
- local runService = game:GetService("RunService")
- local flying = false
- local flySpeed = 50
- -- Create BodyVelocity to control movement
- local bodyVelocity = Instance.new("BodyVelocity")
- bodyVelocity.MaxForce = Vector3.new(1e6, 1e6, 1e6) -- Allow strong forces
- bodyVelocity.P = 10000 -- Powerful force to counteract gravity
- -- Create BodyGyro to lock orientation smoothly
- local bodyGyro = Instance.new("BodyGyro")
- bodyGyro.MaxTorque = Vector3.new(1e6, 1e6, 1e6) -- Allow strong torque in all directions
- bodyGyro.P = 5000 -- Higher stabilization power for faster response
- bodyGyro.D = 150 -- Damping to smooth out rotation transitions
- -- Disable falling animation by preventing unwanted state changes
- local function disableFallingAnimation()
- humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false) -- Prevent falling state
- humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false) -- Prevent ragdoll physics
- end
- -- Enable all default animations and states after flying
- local function enableNormalAnimations()
- humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
- humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
- end
- -- Update movement and orientation continuously
- local function updateFlight()
- if flying then
- -- Update velocity to move forward
- bodyVelocity.Velocity = rootPart.CFrame.LookVector * flySpeed
- -- Smoothly rotate to face forward
- bodyGyro.CFrame = rootPart.CFrame
- end
- end
- local function onInputBegan(input, gameProcessed)
- if gameProcessed then return end
- if input.KeyCode == Enum.KeyCode.Space and not flying then
- flying = true
- -- Attach BodyVelocity and BodyGyro to the root part
- bodyVelocity.Parent = rootPart
- bodyGyro.Parent = rootPart
- disableFallingAnimation() -- Stop falling animation
- -- Start updating flight
- runService.RenderStepped:Connect(updateFlight)
- end
- end
- local function onInputEnded(input, gameProcessed)
- if input.KeyCode == Enum.KeyCode.Space and flying then
- flying = false
- -- Remove BodyVelocity and BodyGyro
- bodyVelocity.Parent = nil
- bodyGyro.Parent = nil
- enableNormalAnimations() -- Restore animations
- end
- end
- -- Enable jumping while flying
- local function onJumpRequest()
- if flying then
- humanoid:ChangeState(Enum.HumanoidStateType.Jumping) -- Force jump state
- end
- end
- userInputService.InputBegan:Connect(onInputBegan)
- userInputService.InputEnded:Connect(onInputEnded)
- humanoid:GetPropertyChangedSignal("Jump"):Connect(onJumpRequest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement