Jump animation from AnimatedSprite

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

Hi :slight_smile: I have animation for walk left, right and jump.
All of the animations works, but not the jump.

I cant seem to figure out the problem. So i am here to ask for help.

const UP = Vector2(0, -1)
const GRAVITY = 100
const MAXSPEED = 100
const MAXGRAVITY = 200
const JUMPSPEED = 800

var movement = Vector2()

 func _physics_process(delta):
if Input.is_action_pressed("ui_left"):
	movement.x = -MAXSPEED
	$AnimatedSprite.play("Walk")
	$AnimatedSprite.set_flip_h(false)
elif Input.is_action_pressed("ui_right"):
	movement.x = MAXSPEED
	$AnimatedSprite.play("Walk")
	$AnimatedSprite.set_flip_h(true)
else:
	movement.x = 0
	$AnimatedSprite.play("Idle")
	
if is_on_floor():
	if Input.is_action_just_pressed("ui_up"):
		movement.y = -JUMPSPEED
		$AnimatedSprite.play("Jump")
	

movement.y += GRAVITY

if movement.y > MAXGRAVITY:
	movement.y = MAXGRAVITY
	
movement = move_and_slide(movement, UP)
:bust_in_silhouette: Reply From: exuin

Hi, I think the issue is that the “idle” animation is overriding the “jump” animation. Before playing the idle animation, you should check to see if the player is not jumping at the moment.

Thank you for the response. How will i go about doing that?
I am new to Godot and making games. So my knowledge isn’t that great.

Normalize | 2021-09-16 17:10

elif is_on_floor():
    movement.x = 0
    $AnimatedSprite.play("Idle")

exuin | 2021-09-16 17:16

:bust_in_silhouette: Reply From: Grizly

Good day. Between your animations dissonance.
When your heroe jumping changes vector.y but vector.x = 0 and this is identically animation “Idle”.
Based on your condition:
if is_on_floor():
$AnimatedSprite.play(“Jump”)

But when you jumping you don’t stayon floor. Invalid animation condition.

I would code it like this:

var const UP = Vector2(0, -1)
var const GRAVITY = 100
var const MAXSPEED = 100
var const MAXGRAVITY = 200
var const JUMPSPEED = 800
var movement = Vector2(ZERO)

func _physics_process(delta):
movement = move_and_slide(movement, UP)
movement.y += GRAVITY
if movement.y > MAXGRAVITY:
movement.y = MAXGRAVITY
move()
animation_update()

func move():
if Input.is_action_pressed(“ui_left”):
movement.x = -MAXSPEED
elif Input.is_action_pressed(“ui_right”):
movement.x = MAXSPEED
else:
movement.x = 0

if is_on_floor():
if Input.is_action_just_pressed(“ui_up”):
movement.y = -JUMPSPEED

func animation_update():
is_on_floor():
if movement.x != 0:
$AnimatedSprite.play(“Walk”)
elif movement.x == 0:
$AnimatedSprite.play(“Idle”)
is_on_floor() == false:
if movement.y < 0:
$AnimatedSprite.play(“Jump”)
if movement.y > 0:
$AnimatedSprite.play(“Fall”)

    

I apologize for no indents. The editor ignores my indentation.

Grizly | 2021-10-06 07:54