how could i add a jump animation to this?

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

so i wanna make a game like mario bros and idk how to add a jump animation to this
so yeah! (i have already coded the rest tho)

thank you!

func _process (delta):
 if Input.is_action_pressed("left"):
	  $AnimatedSprite.play("walking")
	  $AnimatedSprite.flip_h = true
 elif Input.is_action_pressed("right"):
	  $AnimatedSprite.play("walking")
	  $AnimatedSprite.flip_h = false
 else:
	  $AnimatedSprite.play("idle")

2D Movement in Godot in Only 4 Minutes

sarapan_malam | 2022-09-13 15:53

:bust_in_silhouette: Reply From: Wakatta

You can add as much conditions as needed using elif

func _process (delta):
    if Input.is_action_pressed("left"):
         $AnimatedSprite.play("walking")
         $AnimatedSprite.flip_h = true
    elif Input.is_action_pressed("space"):
         $AnimatedSprite.play("jumping")
         #increase jump velocity
    elif Input.is_action_pressed("right"):
         $AnimatedSprite.play("walking")
         $AnimatedSprite.flip_h = false
    else:
         $AnimatedSprite.play("idle")

might want to test if the jump animation is not already playing to avoid jumping endlessly

thank you very much!

summertime_enjoyer | 2022-09-15 11:06