idle and run animations aren't playing

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

I’m making a 2D platformer and it was all working fine but when I restarted Godot, it somehow messed up, the idle and run animations aren’t playing anymore, I checked the code and everything is working but when I play the scene, the idle and run animations aren’t playing…

This is the player script:

extends KinematicBody2D
class_name Player

enum { MOVE, IN_AIR }



export(Resource) var moveData

var double_jump = 1
var speed = Vector2.ZERO
var state = MOVE

func _physics_process(delta):
	var input = Vector2.ZERO
	input.x = Input.get_axis("ui_left", "ui_right")
	input.y = Input.get_axis("ui_up", "ui_down")
	
	match state:
		MOVE: move_state(input)
		IN_AIR: air_state(input)
	
	
		
func move_state(input):
	
	apply_gravity()
	if speed.y > 0:
		$AnimatedSprite.animation = "Fall"
		speed.y += moveData.AdditionalFallGravity
	
	if input.x == 0:
		apply_friction()
		$AnimatedSprite.animation = "Idle"
		print("idle")
	else:
		apply_acceleration(input.x)
		$AnimatedSprite.animation = "Run"
		print("run")
		if $DustTimer.is_stopped() and is_on_floor():
			$Particles2D.emitting = true
#			$DustTimer.start($Particles2D.lifetime + 0.1)
		if input.x > 0:
			$AnimatedSprite.flip_h = false
			$Particles2D.set_rotation_degrees(180)
		elif input.x < 0:
			$AnimatedSprite.flip_h = true
			$Particles2D.set_rotation_degrees(0)
			
			
	if is_on_floor():
		double_jump = moveData.DoubleJumpCount
		if Input.is_action_just_pressed("ui_up"):
			speed.y = moveData.JumpForce
	else:
		$AnimatedSprite.animation = "Jump"
		if Input.is_action_just_released("ui_up") and speed.y < moveData.JumpReleaseForce:
			speed.y = moveData.JumpReleaseForce
		
		if Input.is_action_just_pressed("ui_up") and double_jump > 0:
			speed.y = moveData.JumpForce
			double_jump -= 1
			state = IN_AIR
			
		
		if speed.y > 0:
			speed.y += moveData.AdditionalFallGravity

	var was_in_air =  not is_on_floor()
	speed = move_and_slide(speed, Vector2.UP)
	var just_landed = is_on_floor() and was_in_air
	if just_landed:
		$AnimatedSprite.animation = "Run"
		$AnimatedSprite.frame = 1
		
	
func air_state(input):
	$AnimatedSprite.animation = "Double_Jump"
	print("double jump")
	if double_jump < 1:
		state = MOVE
		print("moved to state")
	
	
	
func apply_gravity():
	speed.y += moveData.Gravity
	speed.y = min(speed.y, 300)
func apply_friction():
	speed.x = move_toward(speed.x, 0, moveData.Friction)
	

func apply_acceleration(amount):
	speed.x = move_toward(speed.x, moveData.MaxSpeed * amount, moveData.Acceleration)

Think you must use $AnimatedSprite.play(ANIMATIONNAME) instead of a $AnimatedSprite.animation = ANIMATIONNAME

zeludtnecniv | 2023-01-31 11:25