Jump after the end of the animation

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

Hi,
I can’t figure out how I can make my player jump only after that the “jumping” animation is finished. I tried a lot of things but my player now jump when he does the animation and i don’t want it.
Thank you for the help

:bust_in_silhouette: Reply From: supper_raptor

If you are using animation player, connect signal

_on_AnimationPlayer_animation_finished(anim_name):

so code would be

func _on_AnimationPlayer_animation_finished(anim_name):
    if anim_name == "jump":
        ready_to_jump = true

It doesn’t work, this is the part of my player(kinematicBody2D) code with the “jump”
function

func jump():

   if Input.is_action_pressed("jump") and is_on_floor():
	  $AnimatedSprite.play("jump")
	
   if ready_to_jump==true:
	  movimento.y-=JUMP_SPEED			


func _on_AnimatedSprite_animation_finished(anim_name):
   if anim_name=="jump":
	  ready_to_jump=true

It does the jump animation but it doesn’t jump , maybe i made a mistake on the signal but i don’t know

Matteo | 2020-04-06 08:51

It should be

if Input.is_action_pressed("jump") and is_on_floor() and ready_to_jump==true:
    $AnimatedSprite.play("jump")

supper_raptor | 2020-04-06 11:36