Animations not loading via script

The fuction:

func _physics_process(delta):

if not is_on_floor():
	velocity.y += get_gravity(velocity) * delta
	animated_sprite_2d.play("Jump")

if Input.is_action_just_released("Up") and velocity.y < 0:
	velocity.y = JUMP_VELOCITY / 4
	
if Input.is_action_just_pressed("Up") and is_on_floor():
	velocity.y = JUMP_VELOCITY
	


if Input.is_action_pressed("Left"):
	velocity.x = -SPEED
	animated_sprite_2d.animation = "Walk"
	$AnimatedSprite2D.flip_h = true
	if Input.is_action_pressed("Left") and Input.is_action_pressed("Sprint"):
		velocity.x = -SPEED * 2
elif Input.is_action_pressed("Right"):
	velocity.x = SPEED
	animated_sprite_2d.animation = "Walk"
	$AnimatedSprite2D.flip_h = false
	if Input.is_action_pressed("Right") and Input.is_action_pressed("Sprint"):
		velocity.x = SPEED * 2

else:
	velocity.x = 0
	animated_sprite_2d.animation = "Idle"

move_and_slide()

Problem:

Jumping animation don’t “load” after starting the game. There’s no errors about that piece of script so i don’t know why is it happening.

Help will be appreciated.

Is the jump working? If so then try this:

animated_sprite_2d.play("Jump")

It isnt working either.

I know why its not working, try this:

if not is_on_floor():
	velocity.y += get_gravity(velocity) * delta
	animated_sprite_2d.play("Jump")

if Input.is_action_just_released("Up") and velocity.y < 0:
	velocity.y = JUMP_VELOCITY / 4
	
if Input.is_action_just_pressed("Up") and is_on_floor():
	velocity.y = JUMP_VELOCITY
	


if Input.is_action_pressed("Left"):
	velocity.x = -SPEED
	if is_on_floor(): animated_sprite_2d.animation = "Walk"
	$AnimatedSprite2D.flip_h = true
	if Input.is_action_pressed("Left") and Input.is_action_pressed("Sprint"):
		velocity.x = -SPEED * 2
elif Input.is_action_pressed("Right"):
	velocity.x = SPEED
	if is_on_floor(): animated_sprite_2d.animation = "Walk"
	$AnimatedSprite2D.flip_h = false
	if Input.is_action_pressed("Right") and Input.is_action_pressed("Sprint"):
		velocity.x = SPEED * 2

else:
	velocity.x = 0
	if is_on_floor(): animated_sprite_2d.animation = "Idle"

move_and_slide()

Thanks bro. That helped me alot.

1 Like

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