Falling animation

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

So I’m trying to make my character have a falling animation that plays if the player doesn’t press the jump button but still goes off a ledge. I’m still pretty new to this so I don’t know if I have to rearrange my whole animation code or just add something.

func _process(delta):
if on_floor == false:
	if Input.is_action_pressed("Jump"):
		$AnimatedSprite.play("Jumping") 
elif is_on_floor():
	if Input.is_action_pressed("ui_right"):
		$AnimatedSprite.play("Running")
	elif Input.is_action_pressed("ui_left"):
		$AnimatedSprite.play("Running")
	elif Input.is_action_pressed("Jump"):
		$AnimatedSprite.play("Idle")
	else:
		$AnimatedSprite.play("Idle")
:bust_in_silhouette: Reply From: Lopy

You can add a “jumped” variable, set to true on jump, false on landing. Then, if you are off the ground, didn’t jump and haven’t started the falling animation, start it.

:bust_in_silhouette: Reply From: FirePrincessITA

Maybe just make it check if the velocity is positive (aka the player is going down)

The code I use for my movement animations are as follows.

=== ANIMATIONS ===

if is_on_floor() and velocity.y == 0:
	if (velocity.x > 1 || velocity.x < -1):
		animated_sprite_2d.animation = "run"
	elif attacking == false:
		animated_sprite_2d.animation = "idle"
elif velocity.y > 0:
	animated_sprite_2d.animation = "fall"
else:
	animated_sprite_2d.animation = "jump"

The first checks to see if my Y velocity is 0 AND I’m on ground. If so, I play the run or idle animations. Then if I am falling, which is the greater than 0. I play falling. All other times, I’m jumping. Only way I could get Jump to work for me.