Hello, I’m trying to make a system where I either equip a tool or more importantly press a key and it’ll change lets say my idle or my walk, ect. How could I change animations and then be able to change them back at will? Is there a way to find lets say all animation tracks being run by the humanoid and then updating them to certain id’s or would I need some finesse?
Any and all help means the world to me, I’m a solo dev trying to learn every form of development and scripting has been my achilles heel but I’m still progressing.
I believe you can play an animation at a time. So putting Animation:Play() should just stop the animation played before and play the one you are telling to play.
This maybe wrong as I don’t have much experience with animations.
I’ve tried switching animations before and they just play over each other and look weird, I’m basically trying to swap the characters idle and keeping it that way, but not sure how.
I would recommend loading the animation using Humanoid:LoadAnimation() at the start of a local script inside of the tool. Then using an event for when the tool is equipped, use Animation:Play() on the LoadAnimation() function to play the animation. Similarly, you can also use Animation:Stop() on the LoadAnimation() when the tool is unequipped to stop the animation.
If the animation does not loop, make sure you set it looped when creating the animation in the animation editor and setting the animation priority to idle may also help.
Thing is if I’m not mistaken, that method would fuse animations and play both animations at half, cause lets say jump animations or fall animations, how would that animation system recognize any of that, would that animation just keep playing, like lets say a run animation would just keep playing when I run, or would I have ot go so far as to detecting humanoid state and change the animation based on that? Wish there was a simpler way of changing animations.
If it’s the simple movement animations that you would like to replace then just duplicate the local “Animate” script inside of the player’s character and paste it into the StarterPlayer > StarterCharacterScripts. Afterward, just find the right Animation instance under the “Animate” script and change the AnimationId.
There is no function that will return you all the loaded animation tracks but there is a function that gets the current playing ones using Humanoid.Animator:GetPlayingAnimationTracks()
I tried that and it’d play the animations at half, unless I did it wrong. You’re suggesting basically having 2 animate scripts within the character right?
After reading the solution that what It would do. I mean when we play animations they are inside of player character, aren’t they? Try it with a new script.
And This is what you are looking for…
Stop all playing animations for a certain player (the same code from the documentation :
local animator = humanoid:WaitForChild("Animator")
-- Stop all animation tracks
for _, playingTrack in animator:GetPlayingAnimationTracks() do
playingTrack:Stop(0)
end