How to detect animation is blending?

Godot Version

godot 4.2.1

Question

play a foot sound, when the character moves, in each animation (walking, running, aiming) the moment the left foot touches the ground and the moment the right foot touches the ground

As shown in the image below, we played the footstep sound using the method call key frame
transitionman

Walking, running, and aiming walking were handled using an animation tree, and the transitions between each animation used a state machine within the animation tree.

When switching between states, the time is set to 0.2 seconds on xfade, and the curve is set to an upward-right straight line
footstepman

When i do this, the footsteps play well, but it’s also played in blending between animations, the method call keyframe of each animation works

Sound is just playing at the same time.

Is there a way to block the call of a keyframe event on the other side when the animation is blending or to detect if the animation is currently blending?

1 Like

I only know that AnimationPlayer has a signal called “is_playing()”, which can be used to check if this AnimationPlayer is playing any animation

I’m late to the party, but I had a similar problem and found this forum post. I fixed this issue by using an if statement in the function that gets triggered by the animation:

if(animationStateMachine.GetCurrentNode() == "Shooting")
{
    gunAnimationPlayer.Play("Shooting");
}

The documentation says the following about GetCurrentNode():

Returns the currently playing animation state.
Note: When using a cross-fade, the current state changes to the next state immediately after the cross-fade begins.

This means that when the AnimationState starts blending, the GetCurrentNode() already returns the new state.

I’m using C# for my project, but it should be similar in GDscript.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.