hey, I have an animation and I want to measure how long it takes for the animation to get from 1 keyframe to another keyframe, but I’m not sure how to do so…
could someone please recommend me tips to achieve this? thanks in advance!
hey, I have an animation and I want to measure how long it takes for the animation to get from 1 keyframe to another keyframe, but I’m not sure how to do so…
could someone please recommend me tips to achieve this? thanks in advance!
Are you trying to time something to an animation?
Use the following service, KeyframeSequenceProvider
with
local KeyframeSequence = KeyframeSequenceProvider:KeyframeSequenceProvider(animationId)
|local Keyframes = KeyframeSequence:GetKeyframes()
Finally loop through them all and to get the time use Keyframe.Time
Then get the time difference: dt = t2 - t1
, now you are done.
yes I am, I’m trying to make a fireball throwing animation thingy haha
Alright, I’ll try that, thank you!
oh by the way, how do I make measure from 1 keyframe to another, your solution only told me to get all the keyframes and get the time (sorry I had to un-solution your post, it didn’t really fit the title)
When you have the times of the keyframes you want to measure you can subtract them to get the time in between them.
So basically something like
local delta = secondKeyframe.Time - firstKeyframe.Time
Subtract the first from the second because the second keyframe is later, so the time value is higher. If you do it the other way around the result will be negative.
Am I doing this correctly?
local keyframeTime = 0
local times = 0
local ksp = game:GetService("KeyframeSequenceProvider")
local ff = 0
local sf = 0
local KeyframeSequence = ksp:GetKeyframeSequenceAsync(tool.Animation.AnimationId)
local Keyframes = KeyframeSequence:GetKeyframes()
for i, keyframe in pairs(Keyframes) do
if times < 2 then
if times == 1 then
ff = keyframe.Time
elseif times == 2 then
sf = keyframe.Time
end
times += 1
end
end
print("First frametime: "..ff)
print("Second frametime: "..sf)
I’m not sure what you’re trying to do?
If you are trying to get the time between the first 2 keyframes you can just do
ff = Keyframes[1].Time
sf = Keyframes[2].Time
If you want to get the time between every 2 keyframes you’ll need an array to store those times.
I’m trying to get the time it takes to get from 1 point to another
I don’t know how to do it tho… unless I use an os.time
timer to figure it out
Yes, but which 2 points? The first 2 points? Or 2 specific points in the middle of the animation?
I think the distance between the animation event?
The first two points are the fireball charge up, the last two are throwing the fireball, so I want to get the third animation point
Then it would be either
ff = Keyframes[2].Time
sf = Keyframes[3].Time
or
ff = Keyframes[3].Time
sf = Keyframes[4].Time
Depending on what time you want to measure.
so this will get how long it is from keyframe 1 to keyframe 3?
local keyframeTime = 0
local times = 0
local ksp = game:GetService("KeyframeSequenceProvider")
local KeyframeSequence = ksp:GetKeyframeSequenceAsync(tool.Animation.AnimationId)
local Keyframes = KeyframeSequence:GetKeyframes()
local ff = Keyframes[1].Time --Charge up
local sf = Keyframes[3].Time --Throw
print("Calculated time: "..(ff + sf))
No you have to subtract ff from sf.
But in the case that you want to measure the distance between point 3 and the start of the animation you can just do
local calculatedTime = Keyframes[3].Time
oh alright, I’ll try that right now and I’ll notify you on if it works or not, thank you so much!
My bad, I did not see your initial reaction , alright so we will first need to loop through the keyFrames, because we are not quite sure if they are ordered from shortest time to longest time.
For this we will use table.sort
local Keyframes = ...
table.sort(Keyframes, function(a,b)
return a.Time > b.Time
end)
Now I am not quite sure what you want, but now you can easily get the time difference per keyframe, just loop through the table.
P.S. Could you elaborate on what you want to achieve after this exactly?
It works! Thank you very much!