How to Play an animation while running

Hi guys,

I am not sure if this is the correct section as this is not exactly scripting; but more animations. If so then please let me know which section this should be in and I will remove it, and move it there.

Basically I have charging jump in game. I want to make an animation so that the player can see that the character is charging, as I don’t want to have a GUI for this.

That said, I plan on making two animations. 1 for when the player is just standing still, and one for when they’re running.

However, I am unsure of how to make this charging animation overlap and play at the same time with my running animation.

Actually, I do not even know if this is possible. I basically just want the torso and and arms to move in the charging animation, while the legs are still running.

If anyone can clarify whether or not this is possible; and if it is, please give me a little bit of insight on how I would go about doing it, that would be great!

Couldn’t you just not animate the legs in the charging animation.

The charging animation won’t overlap the walking anims for the legs if it’s not animated.

I have tried this but it does not seem to work for me for some reason.

I suppose it may be a problem with the priority I used?

-- a localscript placed in `StarterCharacterScripts`

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

humanoid.Running:Connect(function(speed)
    if speed > 16 then
        -- play run
    elseif speed  > 0 then
       -- play walk
    else
       -- stop both animations
       -- play idle
    end
end)

make sure you not playing animations that are already playing

2 Likes

It could be a priority issue, but if it isn’t - make sure the legs have no keyframes. Even if they don’t move in your animation, it may have a keyframe that keeps it in place from the start/end of the animation which would override the run animation for the legs.

1 Like

Priority will only affect the limbs that are actually animated. So chances are the legs were actually being used by the charging animation. Therefore it probably is an animation issue, make sure to delete unused keyframes like tralalah suggested.

X animation may have higher priority than Y but if X isn’t utilising the legs while Y is, Y has higher priority over the legs and X has no means of overriding Y.

However if it is absolutely necessary to be handled from the script rather than the animations, then here’s a potential solution.
Note: I can’t say it’s efficient but it works.

  • Preload both animations.
  • Upon stopping/running, have a check see if a bool for charging is set to true. If the check passes run :Play() on the desired animation and :Stop() the other regardless of whether or not it’s playing.
  • Once you’re done “charging” just set the bool to false and run :Stop() on both of the animations, the bool will prevent the animations from being played when they’re not meant to.
  • Whenever you want to start the animations pass a check to see what it’s doing, set the bool to true then play the the proposed animation, while the bool is true it’ll set swap out the animations automatically.

To determine if the player has stopped, or is moving you can use Humanoid.Running and Humanoid.MoveDirection as LiamKyd suggested.

1 Like

You should Duplicate the character’s “Animate” script (Should look like a ‘Local script’), now put it in StarterPlayer where you can put the character scripts in. Then use the scripts you want to perform animation on to connect to the Animate script’s animation values. You should be able to add a animation id of choice inside the animation values of your choice, whether it would be “Running” or “Idle”. Let me know if you have problems.

Note: The animation script automatically plays animation at any state.

1 Like