Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I find the time between two keyframes in an animation using a script?

I'm trying to make a plugin that will convert animations into CFrame:Lerp() and to do this, I need to find the time between keyframes.

Say your keyframes are 1, 2, and 3. I need to find the time between 1 and 2, then between 2 and 3.

How would I do this?

1 answer

I don't think you're taking this straightforward; the math is perfectly straightforward.

Keyframes have a property called Time which gives you their time position in the AnimationTrack. How do you get Keyframes? Keyframes are acquired from an animation's KeyframeSequence. This is usually created when viewing the animation in the animation editor.

Anyway, the math is pretty easy:

local f1 = script.Parent.Frame1
local f2 = script.Parent.Frame2
local f3 = script.Parent.Frame3
-- The above variables all refer to keyframes

local diff1 = f2.Time - f1.Time -- Difference between f2 and f1
local diff2 = f3.Time - f2.Time -- Difference between f3 and f2

I personally think you just forgot about the Time property of keyframes. Note that these 3 in particular are all related to the same body part and have different time positions.

This discussion is preserved as it was. New answers, comments, and votes are closed.