If the jump button is pressed then the character moves up however the animation doesnt play. I have a feeling it could be due to the animation being overwritten but i cant figure out why. I have recently added a stamina system and that works fine but the jump animation no longer works. This is probably an easy fix but I don't have the technical skills to figure it out yet. Thanks in advance.
#Issue with jump animation.
43 messages · Page 1 of 1 (latest)
Well to be honest, this is a little confusing, but can you write in the play animation code to check if the code is working.
If is_on_floor():
---
else:
Animated_sprite.play("jump")
Print("it works")
yup it is printing "it works" it just doesnt play the animation
Hm, strange, how many times does it print that when the player isn't on the ground?
I think i know what's going on, can you see what's logic going on in # duck?
It is saying if the down arrow key is not pressed then the "still" animation shall play
You check this theory, we can use a code to check what's the current animation is playing, with that we can see which animation is playing when you press jump, i think the code goes like this :
if $AnimatedSprite2D.is_playing():
print("Currently playing:", $AnimatedSprite2D.animation)
else:
print("Not playing any animation")
yeah something is not right
it prints many times
What's the error?
Oh, the code is ok but the placement of it is wrong, you can see godot saying unexpected
so do i need to move it somewhere?
hopefully you caan see
Yup, so the problem is, ">|", can you see those indents before the other if statements? That's what we want, just go in the front of if $aninayed2d.isplaying(). Then press TAB
I am talking about these guys if I wasn't clear
cool, i got that working but for some reason its playing the jump animation aparently?
i just cant see it
maybe it is helpfull to know a bit more about it? there are a couple animations i have, still is a slowed down idle, idle is a sort of breathing animation, run is an animation for moving, and jump bassically acts as a falling animation. i shouldve named thewm better but oh well
i figured out how to fix the jump but now my character has the idle animation even when stamina is full and also the run animation when not even moving sometimes. im verry confused now lol
Lol, how did you fixed the jump animation problem?
Well your jump animation is not that different, maybe it is playing but just isn't getting noticed?
oh i just spent the time re-writing the code and made it a bit more thought out and simpler
i have also fixed the running problem it is just the idle being played even at max stamina that i cant fix
it will play the still animation at the start when the stamina is full but as soon as the stamina is below max, even if it returns to max the idle animation still plays
You code is little bit repetitive, so Maybe try something like this:
# Play animations
if is_on_floor():
if direction == 0:
if stamina == max_stamina:
animated_sprite.play("still")
else:
animated_sprite.play("idle")
else:
animated_sprite.play("run")
else:
animated_sprite.play("jump")
yeah i see how my code was a bit crazy thanks for cleaning it up. im still having the issue with idle being played even at max stam
Well for that we have to see if the stamina is actually equal to max_stamina because if idle animation is still playing that means stamina is not equal to max, can you print stamina to make sure it's the same value as the max one?
I have a label that already displays stamina and even when it is max it doesn’t play the still animation
Well that's complicated i guess, can you share you project? So that i can view you entire code and then fix it?
Yeah sure how would I do that?
You can compress the project file and then share it here, you can find the project file's location from godot or just go to the documents folder and see if you are able to get the file
Haha we all were there at some point, i mean i am still there but no worries lol, i will check the code and tell you the problem
So i got the problem, it's that you are adding the stamina in float not in integers, meaning the stamina is going 90,90.1,90.2, which makes it 100.0048 or something like that, meaning it's not == to max_stamina(100). So the code doesn't work, two simple fixes, add the stamina with integers, not with delta(it's a float value), or just write if stamina >= max_stamina :
Play animation sprint.
I hope i explained correctly lol
If not, then in summary, the "stamina" variable value is going above 100(max value), so it doesn't work, simple fix is just write if stamina >=max_stamina:
Nice. What does >= mean just so I understand it?
Also I used delta so it would slowly increase or decrease the stamina but I don’t know another way of doing that tbh
Well >= means greater or equal, it is used when we want something to happen when a value is either == 100 or is > than 100. In our case the stamina was going beyond 100, so we just said, if stamina is equal to or is greater than 100(max_stamina) then do something
Well there are like alot, using timers, making function for adding something, etc, you can search online for simple ones to add only integer numbers(without using delta ofc)
Damn thanks so much for the help your a life saver. Got it working now thanks to you and thanks for explaining everything aswell.