check frametime of the current animation in animationplayer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nooberdev

hi.

i want to check how far into an animation my node is. as an example, i want to check for button input during the last 2 out of 6 frames of an animation, so i can transition into another animation. if the input is true AND the animationplayer has reached a certain point at the current animation, i want to transition into another animation.
how do i check if i reached a specific time/frame during an animation?

is the seek() member function of the animationplayer node for this kind of things? i could not find an explanation online what the seek() function does.

:bust_in_silhouette: Reply From: nooberdev

ok now i have added a function call in the animationplayer setting a bool. i hope this works out.

this solution worked. i just set a function call at the desired time and switched a bool to true. at the start i have set a function call to switch the bool to false. sometimes you gotta squeeze your brain.

nooberdev | 2018-07-14 16:39

It’s wonderful that you figured out the question. Though is there any way you can show some of your code? :wink:

Ertain | 2018-07-14 17:30

It is still spaghetti code at this point and i doubt that it could help anybody out, but User Diet Estus’ solution is now what does the job in a more elegant way than it was before.
Sorry for late reply, went on vacation.

nooberdev | 2018-07-25 10:43

All’s well that ends well, I guess.

Ertain | 2018-07-25 11:38

:bust_in_silhouette: Reply From: Diet Estus

If you are using an AnimationPlayer to change the frame of a Sprite, you can easily check which frame the Sprite is on using its frame attribute.

For example:

if anim_player.current_animation == "fire" and sprite.frame in [4, 5]:
    if Input.is_action_just_pressed("attack"):
        # do something
        pass

This is probably easier than building function calls into your animations to change bools.

thank you, this is exactly what i was looking for.
i marked your reply as best answer and will refactor my code.
thank you again!

nooberdev | 2018-07-25 10:36