wait(1) local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local Player = Players.LocalPlayer --================================================== -- CONFIGURACIÓN --================================================== local NORMAL_SPEED = 80 local FAST_SPEED = 160 local Flying = false local Fast = false local GoingUp = false local GoingDown = false local Character local Humanoid local Root local Animate local Animator local FlightVelocity local FlightAttachment local RunTrack local IdleTrack --================================================== -- BUSCAR IDLE --================================================== local function FindIdleAnimation() if not Animate then return nil end local IdleFolder = Animate:FindFirstChild("idle") if not IdleFolder then return nil end for _, Object in ipairs(IdleFolder:GetChildren()) do if Object:IsA("Animation") then return Object end end return nil end --================================================== -- BUSCAR RUN > RunAnim --================================================== local function FindRunAnimation() if not Animate then return nil end local RunFolder = Animate:FindFirstChild("run") if not RunFolder then return nil end local RunAnimation = RunFolder:FindFirstChild("RunAnim") if RunAnimation and RunAnimation:IsA("Animation") then return RunAnimation end -- Por si el nombre cambia pero sigue siendo -- una Animation dentro de run. for _, Object in ipairs(RunFolder:GetChildren()) do if Object:IsA("Animation") then return Object end end return nil end --================================================== -- DETENER ANIMACIONES PERSONALIZADAS --================================================== local function StopCustomAnimations() if RunTrack then RunTrack:Stop(0.1) RunTrack:Destroy() RunTrack = nil end if IdleTrack then IdleTrack:Stop(0.1) IdleTrack:Destroy() IdleTrack = nil end end --================================================== -- CARGAR IDLE --================================================== local function LoadIdle() if not Animator then return end local Animation = FindIdleAnimation() if not Animation then return end local Success, Track = pcall(function() return Animator:LoadAnimation(Animation) end) if Success and Track then IdleTrack = Track IdleTrack.Priority = Enum.AnimationPriority.Action IdleTrack.Looped = true IdleTrack:Play(0.15) IdleTrack:AdjustWeight(1, 0.1) end end --================================================== -- CARGAR RUN --================================================== local function LoadRun() if not Animator then return end local Animation = FindRunAnimation() if not Animation then return end local Success, Track = pcall(function() return Animator:LoadAnimation(Animation) end) if Success and Track then RunTrack = Track RunTrack.Priority = Enum.AnimationPriority.Action RunTrack.Looped = true end end --================================================== -- CREAR FUERZA DE VUELO --================================================== local function CreateFlightForce() if not Root then return end if FlightVelocity then FlightVelocity:Destroy() FlightVelocity = nil end local Attachment = Root:FindFirstChild("RootAttachment") if not Attachment then FlightAttachment = Instance.new("Attachment") FlightAttachment.Name = "CreativeFlightAttachment" FlightAttachment.Parent = Root Attachment = FlightAttachment else FlightAttachment = nil end FlightVelocity = Instance.new("LinearVelocity") FlightVelocity.Name = "CreativeFlightVelocity" FlightVelocity.Attachment0 = Attachment FlightVelocity.RelativeTo = Enum.ActuatorRelativeTo.World FlightVelocity.ForceLimitsEnabled = false FlightVelocity.VectorVelocity = Vector3.zero FlightVelocity.Parent = Root end --================================================== -- ESTABILIZAR PERSONAJE --================================================== local function StabilizeCharacter() if not Root then return end -- Evita que la física lo haga girar o inclinarse. Root.AssemblyAngularVelocity = Vector3.zero -- Si no está subiendo ni bajando, mantiene -- exactamente la misma altura. if not GoingUp and not GoingDown then local Velocity = Root.AssemblyLinearVelocity Root.AssemblyLinearVelocity = Vector3.new( Velocity.X, 0, Velocity.Z ) end end --================================================== -- ACTIVAR ANIMACIONES DE VUELO --================================================== local function EnableFlightAnimations() if not Animate then return end -- Desactivamos Animate mientras volamos para -- que no cambie las animaciones automáticamente. Animate.Enabled = false if Animator then for _, Track in ipairs(Animator:GetPlayingAnimationTracks()) do Track:Stop(0.1) end end StopCustomAnimations() LoadIdle() LoadRun() if IdleTrack then IdleTrack:Play(0.15) IdleTrack:AdjustWeight(1, 0.1) end end --================================================== -- RESTAURAR ANIMACIONES --================================================== local function RestoreNormalAnimations() StopCustomAnimations() if Animate then Animate.Enabled = true end end --================================================== -- EMPEZAR A VOLAR --================================================== local function StartFlying() if Flying then return end if not Character or not Humanoid or not Root then return end if Humanoid.Health <= 0 then return end Flying = true -- Roblox controla naturalmente hacia dónde mira -- el personaje mediante joystick/WASD. Humanoid.AutoRotate = true -- Evita estados físicos que puedan desestabilizarlo. Humanoid:SetStateEnabled( Enum.HumanoidStateType.FallingDown, false ) Humanoid:SetStateEnabled( Enum.HumanoidStateType.Ragdoll, false ) Humanoid:SetStateEnabled( Enum.HumanoidStateType.Physics, false ) Humanoid:ChangeState(Enum.HumanoidStateType.Running) CreateFlightForce() EnableFlightAnimations() end --================================================== -- DEJAR DE VOLAR --================================================== local function StopFlying() if not Flying then return end Flying = false if FlightVelocity then FlightVelocity:Destroy() FlightVelocity = nil end if FlightAttachment then FlightAttachment:Destroy() FlightAttachment = nil end RestoreNormalAnimations() if Humanoid then Humanoid.AutoRotate = true Humanoid:SetStateEnabled( Enum.HumanoidStateType.FallingDown, true ) Humanoid:SetStateEnabled( Enum.HumanoidStateType.Ragdoll, true ) Humanoid:SetStateEnabled( Enum.HumanoidStateType.Physics, true ) Humanoid:ChangeState( Enum.HumanoidStateType.GettingUp ) end if Root then Root.AssemblyAngularVelocity = Vector3.zero end end --================================================== -- TOGGLE --================================================== local function ToggleFlight() if Flying then StopFlying() else StartFlying() end end --================================================== -- CONFIGURAR PERSONAJE --================================================== local function SetupCharacter(NewCharacter) if Flying then StopFlying() end Character = NewCharacter Humanoid = Character:WaitForChild("Humanoid") Root = Character:WaitForChild("HumanoidRootPart") Animate = Character:WaitForChild("Animate", 5) Animator = Humanoid:FindFirstChildOfClass("Animator") if not Animator then Animator = Instance.new("Animator") Animator.Parent = Humanoid end Humanoid.AutoRotate = true RunTrack = nil IdleTrack = nil FlightVelocity = nil FlightAttachment = nil GoingUp = false GoingDown = false Fast = false end if Player.Character then SetupCharacter(Player.Character) end Player.CharacterAdded:Connect(SetupCharacter) --================================================== -- TECLADO --================================================== UserInputService.InputBegan:Connect(function(Input, GameProcessed) if GameProcessed then return end if Input.KeyCode == Enum.KeyCode.H or Input.KeyCode == Enum.KeyCode.F then ToggleFlight() elseif Input.KeyCode == Enum.KeyCode.E then GoingUp = true elseif Input.KeyCode == Enum.KeyCode.Q then GoingDown = true elseif Input.KeyCode == Enum.KeyCode.LeftShift or Input.KeyCode == Enum.KeyCode.RightShift then Fast = true end end) UserInputService.InputEnded:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.E then GoingUp = false elseif Input.KeyCode == Enum.KeyCode.Q then GoingDown = false elseif Input.KeyCode == Enum.KeyCode.LeftShift or Input.KeyCode == Enum.KeyCode.RightShift then Fast = false end end) --================================================== -- CONTROLES MÓVILES --================================================== if UserInputService.TouchEnabled then local PlayerGui = Player:WaitForChild("PlayerGui") local ScreenGui = Instance.new("ScreenGui") ScreenGui.Name = "CreativeFlightMobile" ScreenGui.ResetOnSpawn = false ScreenGui.Parent = PlayerGui local function CreateButton(Name, Text, Position) local Button = Instance.new("TextButton") Button.Name = Name Button.Text = Text Button.Size = UDim2.fromOffset(70, 55) Button.Position = Position Button.BackgroundTransparency = 0.2 Button.TextScaled = true Button.TextColor3 = Color3.new(1, 1, 1) Button.Parent = ScreenGui return Button end local FlyButton = CreateButton( "FlyButton", "FLY", UDim2.new(1, -160, 1, -140) ) local UpButton = CreateButton( "UpButton", "▲", UDim2.new(1, -80, 1, -210) ) local DownButton = CreateButton( "DownButton", "▼", UDim2.new(1, -80, 1, -140) ) local FastButton = CreateButton( "FastButton", "FAST", UDim2.new(1, -160, 1, -210) ) FlyButton.MouseButton1Click:Connect(function() ToggleFlight() end) UpButton.MouseButton1Down:Connect(function() GoingUp = true end) UpButton.MouseButton1Up:Connect(function() GoingUp = false end) DownButton.MouseButton1Down:Connect(function() GoingDown = true end) DownButton.MouseButton1Up:Connect(function() GoingDown = false end) FastButton.MouseButton1Down:Connect(function() Fast = true end) FastButton.MouseButton1Up:Connect(function() Fast = false end) end --================================================== -- SISTEMA DE VUELO --================================================== RunService.RenderStepped:Connect(function() if not Flying then return end if not Character or not Character.Parent or not Humanoid or not Root then return end if Humanoid.Health <= 0 then StopFlying() return end if not FlightVelocity then CreateFlightForce() end if not FlightVelocity then return end --================================================== -- DIRECCIÓN --================================================== -- Usa el movimiento real del Humanoid. -- Esto hace que funcione con WASD y joystick -- sin utilizar la dirección de la cámara. local MoveDirection = Humanoid.MoveDirection local HorizontalDirection = Vector3.new( MoveDirection.X, 0, MoveDirection.Z ) local VerticalDirection = 0 if GoingUp then VerticalDirection += 1 end if GoingDown then VerticalDirection -= 1 end local Speed = Fast and FAST_SPEED or NORMAL_SPEED FlightVelocity.VectorVelocity = (HorizontalDirection * Speed) + Vector3.new( 0, VerticalDirection * Speed, 0 ) -- Mantener estabilidad. StabilizeCharacter() --================================================== -- ANIMACIONES --================================================== if HorizontalDirection.Magnitude > 0.05 then -- Avanzando: RUN if IdleTrack and IdleTrack.IsPlaying then IdleTrack:Stop(0.12) end if RunTrack and not RunTrack.IsPlaying then RunTrack:Play(0.12) RunTrack:AdjustWeight(1, 0.1) end if RunTrack then RunTrack:AdjustSpeed( Fast and 1.5 or 1 ) end else -- Quieto: IDLE if RunTrack and RunTrack.IsPlaying then RunTrack:Stop(0.12) end if IdleTrack and not IdleTrack.IsPlaying then IdleTrack:Play(0.12) IdleTrack:AdjustWeight(1, 0.1) end end end)