Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Animations not wanting to stop?

Asked by 9 years ago

I have a walking animation for my rig, and it's come a long way through numerous headaches. I can feel myself getting super close to a working one.

There are still a few kinks:

-Occasionally the walking animation doesn't stop "mid-animation" while walking on Baseplate, and finishes its current cycle.

<strike> -It never stops while walking on the grass and has this glitchy loop effect </strike>

EDIT: I've actually partially fixed the second one by making the legs canCollide = false. I do still get the weird "must finish cycle" sometimes but it never infinity loops.

Take a look here to see what I mean: http://www.roblox.com/Plight-place?id=215401821

Here's the code; any suggestions on how to make it run smoother or better?

local WalkingAnimation = Instance.new("Animation")
    WalkingAnimation.Parent = script.Parent
    WalkingAnimation.AnimationId = "http://www.roblox.com/Asset?ID=212756854"


local Humanoid = script.Parent.Humanoid
local Torso = script.Parent.Torso

local Walking = false

local animTrack = Humanoid:LoadAnimation(WalkingAnimation)
local currentPlaying = false

function walkState()
    if Torso.Velocity.x ~= 0 or Torso.Velocity.z ~= 0 then
        return true 
    end
    return false
end

function runAnimation()
    if walkState() then

        if not currentPlaying then
            animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
                if keyframeName == "FinalFrame" then
                    currentPlaying = false
                end
            end)    

            currentPlaying = true
            animTrack:Play()
            --print("Playing")
        else
            --print("Inbetween")
        end
    else
        currentPlaying = false
        animTrack:Stop()
        --print("Stopping")
    end
end

while true do
    runAnimation()
    game:GetService("RunService").RenderStepped:wait()
end

Answer this question