Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Create the Tool
- local tool = Instance.new("Tool")
- tool.Name = "FlyTool"
- tool.RequiresHandle = false
- tool.Parent = game.Players.LocalPlayer.Backpack
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local rootPart = character:WaitForChild("HumanoidRootPart")
- local animator = humanoid:FindFirstChild("Animator") or humanoid:WaitForChild("Animator")
- -- Animations (front and jump animation)
- local flyForwardAnim = Instance.new("Animation")
- flyForwardAnim.AnimationId = "rbxassetid://17124063826"
- local jumpAnim = Instance.new("Animation")
- jumpAnim.AnimationId = "rbxassetid://18893417968" -- Replaced with the finalized jump animation ID
- -- Load animation tracks
- local flyForwardTrack = animator:LoadAnimation(flyForwardAnim)
- local jumpTrack = animator:LoadAnimation(jumpAnim)
- -- Variables for flight and movement
- local flying = false
- local speed = 100
- local flightForce = Instance.new("BodyVelocity")
- local bodyGyro = Instance.new("BodyGyro")
- flightForce.MaxForce = Vector3.new(4000, 4000, 4000)
- flightForce.Velocity = Vector3.new(0, 0, 0)
- bodyGyro.MaxTorque = Vector3.new(4000, 4000, 4000)
- bodyGyro.CFrame = rootPart.CFrame
- -- Input Setup
- local UIS = game:GetService("UserInputService")
- local camera = workspace.CurrentCamera
- local moveDirection = Vector3.new(0, 0, 0)
- -- Function to start flying
- local function startFlying()
- flying = true
- flightForce.Parent = rootPart
- bodyGyro.Parent = rootPart
- humanoid.PlatformStand = true -- Disable default humanoid control
- end
- -- Function to stop flying
- local function stopFlying()
- flying = false
- flightForce.Parent = nil
- bodyGyro.Parent = nil
- humanoid.PlatformStand = false
- -- Stop the forward animation
- flyForwardTrack:Stop()
- end
- -- Tool Activated and Deactivated
- tool.Activated:Connect(function()
- if flying then
- stopFlying()
- else
- startFlying()
- end
- end)
- -- Handle Movement Inputs for W and Mobile (only forward movement)
- UIS.InputBegan:Connect(function(input)
- if flying then
- if input.KeyCode == Enum.KeyCode.W or input.UserInputType == Enum.UserInputType.Touch then
- moveDirection = Vector3.new(0, 0, -1) -- Move forward
- if not flyForwardTrack.IsPlaying then
- flyForwardTrack:Play() -- Play forward animation
- end
- end
- end
- end)
- UIS.InputEnded:Connect(function(input)
- if flying then
- if input.KeyCode == Enum.KeyCode.W or input.UserInputType == Enum.UserInputType.Touch then
- flyForwardTrack:Stop() -- Stop forward animation
- end
- end
- end)
- -- Jumping handler
- humanoid.Jumping:Connect(function(isJumping)
- if flying then
- humanoid.Jump = false -- Disable jumping while flying
- else
- if isJumping and not jumpTrack.IsPlaying then
- jumpTrack:Play() -- Play jump animation when jumping
- end
- end
- end)
- -- Stop the jump animation when landing
- humanoid.StateChanged:Connect(function(oldState, newState)
- if newState == Enum.HumanoidStateType.Landed then
- jumpTrack:Stop()
- end
- end)
- -- Flight control and body alignment
- game:GetService("RunService").Heartbeat:Connect(function()
- if flying then
- -- Set flying velocity and direction based on camera orientation
- local camForward = camera.CFrame.LookVector
- flightForce.Velocity = camForward * speed -- Always move forward
- -- Adjust body tilt based on movement (Goku-style flight)
- local tiltAngle = math.rad(-90)
- bodyGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + camForward) * CFrame.Angles(tiltAngle, 0, 0)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement