Turn off Default R15 Fall Animation in flight mode in RobloxStudio with the programming language Lua

25 Views Asked by At

I am developing a game in RobloxStudio and while scripting i found a problem i cant seem to fix

I have attempted several times to disable the default Fall R15 Animation while in flight mode, which is activated by pressing the Space key twice. However, I seem to be missing a step or perhaps doing something incorrectly because I can't figure out how to turn it off. All I want is to utilize an Idle animation when my character is stationary, but despite having four animations assigned to the keys WASD, the fall animation continues to activate whenever I'm in flight mode and not moving. It's proving to be a persistent issue that I can't seem to resolve. Any suggestions would be greatly appreciated.

Demostration: https://youtu.be/Zh1jjabVJbo

I tried changing the Fall animation to an idle animation - didnt work I tried turning it off while on the figlht mode - didnt work I tried multiple solutions already

local UIS = game:GetService("UserInputService")

local last = tick()
local isFlying = false

local flyUpSpeed = 16
local flyDownSpeed = 16


local char = script.Parent
local root = char:WaitForChild("HumanoidRootPart")

function flight(isFlying)
    if isFlying then
        local bv = Instance.new("BodyVelocity")
        bv.MaxForce = Vector3.new(0, 1, 0) * 30000
        bv.Velocity = Vector3.new(0, 0, 0)
        bv.Name = "FlightVelocity"
        bv.Parent = root
    else
        local bv = root:FindFirstChild("FlightVelocity")
        if bv then bv:Destroy() end
    end
end




UIS.InputBegan:Connect(function(input, gameprocessed)
    if gameprocessed then return end
    
    if input.KeyCode == Enum.KeyCode.Space then    
        if (tick() - last) < 0.5 then
            isFlying = not isFlying
            flight(isFlying)
        elseif isFlying then 
            local bv = root:FindFirstChild("FlightVelocity")
            if bv then 
                bv.Velocity = Vector3.new(0, 1, 0) * flyUpSpeed
            end
        end
        last = tick()
    end
    
    if input.KeyCode == Enum.KeyCode.LeftControl then 
        if isFlying then
            local bv = root:FindFirstChild("FlightVelocity")
            if bv then 
                bv.Velocity = Vector3.new(0, -1, 0) * flyDownSpeed
            end
        end
    end
    
    local bv = root:FindFirstChild("FlightVelocity")
    if isFlying and bv then 
        local currentAnim = Instance.new("Animation")
        
        if  input.KeyCode == Enum.KeyCode.W then 
            if playAnim then playAnim:Stop() end
            currentAnim.AnimationId = "rbxassetid://16864466808"
            playAnim = char.Humanoid:LoadAnimation(currentAnim)
            
        elseif input.KeyCode == Enum.KeyCode.A then 
            if playAnim then playAnim:Stop() end
            currentAnim.AnimationId = "rbxassetid://16864540911"
            playAnim = char.Humanoid:LoadAnimation(currentAnim)

        elseif input.KeyCode == Enum.KeyCode.S then 
            if playAnim then playAnim:Stop() end
            currentAnim.AnimationId = "rbxassetid://16864534139"
            playAnim = char.Humanoid:LoadAnimation(currentAnim)

        elseif input.KeyCode == Enum.KeyCode.D then 
            if playAnim then playAnim:Stop() end
            currentAnim.AnimationId = "rbxassetid://16864446697"
            playAnim = char.Humanoid:LoadAnimation(currentAnim)

        else
            if playAnim then playAnim:Stop() end
        end
        
        if playAnim then playAnim:Play() end
    end
end)





UIS.InputEnded:Connect(function(input,gameprocessed)
    if gameprocessed then return end

    if playAnim then
        if UIS:IsKeyDown(Enum.KeyCode.W) then return end
        if UIS:IsKeyDown(Enum.KeyCode.A) then return end
        if UIS:IsKeyDown(Enum.KeyCode.S) then return end
        if UIS:IsKeyDown(Enum.KeyCode.D) then return end
        
        playAnim:Stop()
    end
    



    if input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.LeftControl then
        if isFlying then
            local bv = root:FindFirstChild("FlightVelocity")
            if bv then 
                bv.Velocity = Vector3.new(0,0,0)
            end
        end
    end
end)
0

There are 0 best solutions below