Question about two different jump animations

Godot Version

4.3

Howdy

I’m working on a 2D sidescrolling MegaMan type game and i’d like to have two different jump animations. One for standing still and pressing “jump” (which i call “jump_up” and the other for pressing “jump” and a direction (“left” or “right”) (which i call “jump_up_side”).

I have the “jump_up_side” part figured out.
I have a “player_animation” function that is called in process, which looks like this:

if Input.is_action_pressed("jump") and Input.is_action_pressed("right"):
	$Sprite2D.flip_h = false
	$Sprite2D.play("jump_up_side")
		
if Input.is_action_pressed("jump") and Input.is_action_pressed("left"):
	$Sprite2D.flip_h = true
	$Sprite2D.play("jump_up_side")

and works like a charm.

the other part i do not get to work.

if i go like this:

if Input.is_action_pressed("jump"):
	$Sprite2D.play("jump_up")

it overwrites the other part and only plays the “jump_up” animation all the time.

can someone help me out here?

You just need to improve the code logic a little, there are many ways to do it, for example I prefer this way:

if Input.is_action_pressed("jump"):
	if Input.is_action_pressed("right"):
		$Sprite2D.flip_h = false
		$Sprite2D.play("jump_up_side")
	elif Input.is_action_pressed("left"):
		$Sprite2D.flip_h = true
		$Sprite2D.play("jump_up_side")
	else:
		$Sprite2D.play("jump_up")
1 Like

that was quick, thank you! :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.