Godot Version
4.2.2
Question
Hello all,
I am having a problem that I am hoping that some of you might be able to help with. It is a problem that I am completely out of my depth with. It is adding an animation to the Brackey’s Godot 4 tutorial.
What I have is a 2D platformer where if you jump onto a spike and later get hit by an enemy then the player game loop _physics_process plays an animation, but I only want it to play the animations once, I made the animation to not loop:
The spike scene initiates the contact and sends the variable onSpike to the player with a true value.
That works. What I cannot get at all is how to play the animation and how to only make it play once. The code I have used is this:
#-- on spike----------------------------
if(onSpike == true):
hero_sprite.play("hit");
if (hero_sprite.animation=="hit" and hero_sprite.is_playing() ):
return;
else:
onSpike = false;
print("... onSpike over");
#------------------------------------------
I can hear you laughing from here . There is a definite logic error here, but, I cannot see it. What I see is:
- if onSpike equals true
- play the sprite animation “hit”
- if that animation is playing - don’t do nuthing, return, let it finish
- else its over set onspike to false over and done with
- onSpike is false continue on nothing to see here, move along
but, the hit animation continues ad infinitum and caught in an endless loop no doubt caused by the return and never drops down to: onspike=false. Needless to say I need some help. As always any help is greatly appreciated.
Thankyou and Regards.