I don’t know if something is going over my head here, because this seems like an obvious feature that should be in Studio already, but I’m curious if there’s an event in AnimationTracks that can detect whenever a playing animation has moved along its timeline, as in the frame it’s playing has changed. “KeyframeReached” and “GetMarkerChangedSignal” (to my knowledge) do not fit these requirements, as they both only fire for specific keyframes, defined by a string parameter.
The event would also need to return the frame of the animation that it changed to.
Perhaps there is a different way to do this, but this is essentially what I need:
local AnimationTrack = Humanoid:LoadAnimation(WalkAnimation)
AnimationTrack.FrameChanged:Connect(function(NewFrame)
print("The animation is now on frame ".. NewFrame)
end)
AnimationTrack:Play()
Forgive my ignorance if there is already something like this and it went by me. Thanks.
local player = game.Players:GetChildren()[1]
local character = game.Workspace:WaitForChild(player.Name)
local humanoid = character:WaitForChild("Humanoid")
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://437855404"
local animTrack = humanoid:LoadAnimation(anim)
animTrack.KeyframeReached:Connect(function(keyframeName)
print("Keyframe reached:"..keyframeName)
end)
animTrack:Play()
I am using animations as a way to have camera movement for my FPS system. Since each animation can have correlating camera movement data, it would be nice to be able to move the camera directly in-sync with each keyframe. Currently, I have the camera movements in a RenderStepped loop that starts at the same time I play the animation, so it can sometimes de-sync from the animation if, for example, the game lags.
Because the number of frames in the animation is identical to the number of times the camera should move, I could easily sync them up with the event I articulated in the original post.
I thought this was a good idea, but it doesn’t seem like the TimePosition property triggers a changed signal.
This is the code I have for playing the reload animation. Nothing gets printed into the output. I also tried spawning the event after the :Play() line, but that didn’t work either.