使用编程语言Lua在RobloxStudio中关闭飞行模式下的默认R15坠落动画

问题描述 投票:0回答:1

我正在 Roblox Studio 中开发一款游戏,在编写脚本时我发现了一个似乎无法修复的问题。

我曾多次尝试在飞行模式下禁用默认的 Fall R15 动画,按两次空格键即可激活该动画。然而,我似乎错过了一个步骤,或者可能做错了一些事情,因为我不知道如何将其关闭。我想要的只是在我的角色静止时使用空闲动画,但尽管有四个动画分配给 WASD 键,但只要我处于飞行模式且不移动,坠落动画就会继续激活。事实证明,这是一个我似乎无法解决的持续存在的问题。任何建议将不胜感激。

演示: https://youtu.be/Zh1jjabVJbo

我尝试将秋季动画更改为空闲动画 - 没有成功。 我尝试在飞行模式下将其关闭 - 不起作用 我已经尝试了多种解决方案。

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)
lua game-development roblox roblox-studio
1个回答
0
投票

你应该看看人形机器人的

PlatformStand
属性

char.Humanoid.PlatformStand = true;

再次禁用苍蝇时请务必禁用它!

© www.soinside.com 2019 - 2024. All rights reserved.