Is there a way to delay my character jumping to sync up with the animation?

Hi. Your method is working fine. Thank You. But if You are here, I have one question. In animationSprite2d I use this code:

func _on_animated_sprite_2d_animation_finished():
if([“jump_end”, “jump_start”, “jump_double”].has(animated_sprite.animation)):
animation_locked = false

I used it to Lock animation for proper landing on the ground.

And then I switched to animationPlayer to use delay for my jump start animation. Now I can’t find solution how to change those lines. Maybe You know and can help me?

func _on_AnimationPlayer_animation_finished(anim_name):

	If anim_name == “jump_start” or “jump_end”:
     animation_locked = false 

Is not working and I am not sure what I am doing wrong.

That doesn’t work because the way you’re structuring your if statement

func _on_AnimationPlayer_animation_finished(anim_name):
    if anim_name == "jump_start" or "jump_end":
        animation_locked = false

This if statement will evalute to:

if anim_name == "jump_start" or "jump_end" == true:

As you’re not comparing “jump_end“ against the anim_name, what you’re doing is ask for the engine: Is anim_name equal to “jump_start“ or the string on the right (“jump_end“) is true? As any non-empty string is equal to true, animation_locked = false will be always called.

In this case you can do:

if anim_name == "jump_start" or anim_name == "jump_end":

# Or

if anim_name in ["jump_start", "jump_end"]:
2 Likes

I see. Thank You :slight_smile: