#Issue with jump animation.

43 messages · Page 1 of 1 (latest)

blazing path
#

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.

white sluice
#

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")

blazing path
#

yup it is printing "it works" it just doesnt play the animation

white sluice
#

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")
blazing path
#

yeah something is not right

white sluice
blazing path
white sluice
#

Oh, the code is ok but the placement of it is wrong, you can see godot saying unexpected

blazing path
#

so do i need to move it somewhere?

white sluice
#

Where is it exactly now?

blazing path
#

hopefully you caan see

white sluice
#

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

blazing path
#

cool, i got that working but for some reason its playing the jump animation aparently?

#

i just cant see it

blazing path
#

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

white sluice
#

Lol, how did you fixed the jump animation problem?

white sluice
blazing path
#

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

white sluice
#

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")
blazing path
#

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

white sluice
blazing path
#

I have a label that already displays stamina and even when it is max it doesn’t play the still animation

white sluice
blazing path
#

Yeah sure how would I do that?

white sluice
# blazing path 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

blazing path
#

there you go its probably really messy because this is my first time coding lol

white sluice
white sluice
# blazing path there you go its probably really messy because this is my first time coding lol

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:

blazing path
#

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

white sluice
# blazing path Nice. What does >= mean just so I understand it?

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

white sluice
blazing path
#

Damn thanks so much for the help your a life saver. Got it working now thanks to you and thanks for explaining everything aswell.