Stuck in last frame of animation when button is hammered

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

I have seen a Sidescroller tutorial made in GMS on YouTube and decided it would be a nice exercise to rebuild the project in Godot Engine by using the techniques I have learned so far from the docs.

I am stuck for a week now at the problem described in the title.

I have set up a extremely simple state machine with various states (idle, run, roll, attack1, attack2, attack3) and they work with one exception. The rolling state.

Everything works as intended, but when I hammer the spacebar (which is the button for the roll state), the animation gets stuck in the last frame and does not transition to any other state anymore. To prevent this, i thaught making it mandatory to be in the idle or run state before it gets executed would help. But the problem still occurs. Here is the link to the code in my project.

Github Link to the Player character code

The part with the roll state has a comment (starting at line 49). You are welcome to make a PR. I am still realtively new to the whole version control thing but I guess I can handle it. :smiley:

If something is unclear, I checked the e-mail notifictation for this thread to reply asap.
I really need help so I can sleep peaceful again. This is driving me nuts.

in change_state, you are checking if the new state is different, but you still assign new_anim regardless. Either the if is useless, or was it intented?

To me the culprit could be this:

func _on_Animation_animation_finished(animation):
	match animation:
		"roll", "attack1", "attack2", "attack3":

This will never run before your _process, always after, because the animation player is a child node. Perhaps this callback and your get_input function are running out of order and clash?

Zylann | 2018-07-25 12:45

Hi Zylann, thanks for your time reviewing my code.

The if actually is useless and I now removed it. I think it was just a sign of despair, trying to figure out what is going wrong.

Anyways I noticed a weird behaviour earlier. When attacking (bound to Enter key) and instantly rolling (bound to Spacebar), the character switches to the second attack animation. This might have something to do with the same reason the rolling acts weird.

Thanks for your hint with the AnimationPlayer callback. I need to debug this. Really weird what is happening now. :confused:

nooberdev | 2018-07-25 15:49

Hi Zylann. Can you copy your comment into an answer? I would like to mark it as the best answer. Removing the signal unfortunately did not solve my problem with the animation being stuck, even though it was responsible for some crashes and generally weird behaviour. I think I rework the whole thing with a different approach.

nooberdev | 2018-07-27 12:22

Well, it was not really an answer since the exact problem was not found.

Zylann | 2018-07-27 21:59