So the title pretty much explains what I am asking here - I've made a simple animation that plays when a character fires a gun in my game, but the problem comes with how the default animation interpolation system plays the gun firing animation a little bit too slowly which makes it feel less "powerful", as firing a gun should feel. I have tried looking around on the wiki for a way to set the time position of the animation to a specific keyframe without having to wait for interpolation, but I couldn't find anything.
I wish I could show a couple of Gyazo GIFs to demonstrate the problem, but unfortunately this website doesn't support Gyazo (if there is another way to upload GIFs please let me know). So if it hasn't been clear so far, what I'm looking for is something similar to a CFrame:lerp(goal, 0.5)
function where you can manually set the time position of the interpolation but for AnimationTracks made with the Roblox animation editor.
When an AnimationTrack's Speed
property is equal to its Length
property, the track will be 1 second in length. That being said, you can divide the length by the amount of seconds you want the animation to play to adjust the speed accordingly.
You can change an AnimationTrack's speed using the AdjustSpeed
method.
Taken from here:
function playAnimationForDuration(animationTrack, duration) local speed = animationTrack.Length / duration animationTrack:AdjustSpeed(speed) animationTrack:Play() end
You also don't have to call AdjustSpeed every time you want to play the animation, it can be done after your LoadAnimation initialization in the global scope. i.e
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:wait() local humanoid = character:WaitForChild("Humanoid") local tool = script.Parent local animation = tool.Animation local track = humanoid:LoadAnimation(animation) --load the animation into the humanoid track:AdjustSpeed(track.Length / 0.5) --this track will last for half a second tool.Activated:Connect(function() track:Play() --play the animation when the tool is activated end)
Hope I helped!