attack animation continues to repeat when it should stop after one cycle

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

hi all,

i’m trying to implement a reversal kick. however when i press the attack button, the character continues to do the action and never stops. see example gif:

Animated GIF - Find & Share on GIPHY.

here is the paste bin. note particular line involved which is 23 to 27:

any help would be greatly appreciated

:bust_in_silhouette: Reply From: Pomelo

First of all your code has quite a bit too many bad practice stuff going on. Too many if statements on the one hand and badly named variables on the other. To give an example, we have the source of your problem! You have 2 variables, attacking and isAttacking, which both mean the same thing, and you are setting the fist one to true when pressing the kick, and checking for the second one. Thats why it doesnt work as intended. Stick to one way of naming stuff to avoid these issues (for example, if you stick with “is_doing_stuff” also change your jump to is_jumping). I also recomend reading up on setting up a state machine, since it will make adding more stuff easier on the future!

yes your right. i did start looking at state machines and it does have a much more cleaner and efficient approach . i appreciate the feedback thank you

chris33556 | 2022-07-17 07:14

In _physics_process () and apply_movement () you are performing a jump == false when it should be jump = false (one = character). The former is a boolean comparison and the latter is an assignment, that might be causing issues!

zenbobilly | 2022-07-17 14:21