0 votes

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.

in Engine by (143 points)

2 Answers

0 votes
Best answer

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.

by (1,567 points)
selected by

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!

0 votes

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

by (143 points)

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.

It's wonderful that you figured out the question. Though is there any way you can show some of your code? ;)

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.

All's well that ends well, I guess.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.