为什么我的动画脚本只会播放闲置动画?

我正在为 Roblox 上的自定义角色制作自定义动画脚本。人工智能功能很好,但几乎总是只播放闲置动画,即使有 humanoid 事件。

通常情况下,怪物处于空闲状态时,应该播放闲置动画。当行走时应该播放行走动画。当 AI 攻击时,应该播放攻击动画。

我已经尝试注释掉闲置动画部分,但没有任何动画播放。

以下是代码:

local myHuman = script.Parent.Humanoid
local walkAnim = myHuman:LoadAnimation(script.Parent.Walk)
local idleAnim = myHuman:LoadAnimation(script.Parent.Idle)
local jumpAnim = myHuman:LoadAnimation(script.Parent.Jump)

myHuman.Running:Connect(function(speed)
    if speed > 3 then
        walkAnim:Play()
    else
        walkAnim:Stop()
        idleAnim:Play()
    end
end)

myHuman.Jumping:Connect(function()
    jumpAnim:Play()
end)

myHuman.Died:Connect(function()
    for i,v in pairs(myHuman:GetPlayingAnimationTracks()) do
        v:Stop()
    end
end)
点赞
用户14687315
用户14687315

尝试使用 print 而不是动画,看看会发生什么,告诉我是否有打印出任何内容。

myHuman.Running:Connect(function(speed)
    if speed > 3 then
           print("walk")
       else
           print("start idle")
    end
end)

编辑:https://devforum.roblox.com/t/getplayinganimationtracks-is-deprecated/1075650 我认为你必须使用 myHuman.Animator:getPlayingAnimationTracks()

2021-04-07 00:44:29