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

What would be the best way to run custom animations at a consistent framerate?

Asked by
W8X 95
8 years ago

Using RunService.Heartbeat used to be the best way to do it, but after the behavior change, Heartbeat doesn't run at a consistent framerate anymore. Here's an example of what my animations look like.

for _=0,1,.1 do
    RAW.C1 = RAW.C1:lerp(Target,.4) --Right arm weld
    game:GetService('RunService').Heartbeat:wait() --What would I use to replace this line, that runs at a consistent speed
end

2 answers

Log in to vote
0
Answered by 8 years ago

The delta
Triangles everywhere!

Assuming that your script is trying to do exactly what you're trying to get it to do, your best bet is still just using wait because all of the Heatbeat/Stepped based events are all now linked to the scheduler. Dodgy. You might need to consider what your goal for your lerping is, because I don't want to try and write you some refactored code in case time isn't your goal or limiter.

If you're not sure, you'll need to take into account the difference of time between the first and last heartbeat (delta). It won't happen consistently, which you can't fix without spreading your code over several heartbeats anyway, but it will make your code always work at the same speed regardless of how often the heartbeat occurs.

Ad
Log in to vote
0
Answered by 8 years ago

When it comes to animations, I find it best to synchronize them with render stepped instead and definitely use delta time.

Keeping track of how much time has passed(which is the delta), allows you to keep consistent animation, since you can alter how far to move your part.

local renderStepped = game:GetService('RunService').RenderStepped
local alpha = 0
local original = RAW.C1

repeat
    -- Render stepped already returns delta, which is time diffference since last render step
    local delta = renderStepped:wait()
    -- Alpha will dynamically increase and react to frame drops, since it increases via delta
    -- To slow it up/down you would multiply the delta in equation below. By default, this animation will take 1 second to complete
    alpha = alpha + delta

    -- Definitely keep the original CFrame and use that for lerping, way more reliable
    RAW.C1 = original:lerp(Target, alpha)
until alpha >= 1
-- At the end you want to set the CFrame to end position, in case you lerped it too far
RAW.C1 = Target

Answer this question