Also if animation exists when I play it I cannot see iy playing

Godot Version

`4.0

Question

altougth i play an animation I cannot see it:
Despite I defined code:

extends CharacterBody2D

class_name PlayerController
@export var JUMP_VELOCITY = -800.0
@export var jump_mult = 0.90
@export var anim_Sprite2D: AnimatedSprite2D

after setting an AnimatedSprite2D item which has defined several animations within it: idle_left, walk_right,idle_left, walk_right,jump_left, jump_right, if i try to run one of these also after I update the physics and play it when the “jump” button is pressed:

if Input.is_action_pressed("Jump") and is_on_floor() :
		if(Glob.electricBlock == false):
			velocity.y =jump_mult*JUMP_VELOCITY
			anim_Sprite2D.play("jump_right")


It isn’t played

Can you show more of the code? There’s not enough to tell what the issue is.

ok, I am going to attach all the code:

extends CharacterBody2D

class_name PlayerController


 #to avoid playing animation twice
# @export var SPEED = 250.0
const SPEED = 150.0
#@export var animation_tree:AnimationTree

@export var anim_Sprite2D: AnimatedSprite2D

# @onready var sprite__J: Sprite2D = $Sprite2D

@export var HP =100.0
@export var JUMP_VELOCITY = -800.0
@export var jump_mult = 0.90
@export var falling_mult = 0.90
@export var gravity = 72
@export var falling_mul = 30


var is_jumping = false
var speed_mult = 30.0
var gravity_sys = ProjectSettings.get_setting("physics/2d/default_gravity")
#var direction = 0
@export var electrified= false
var attacking = false
var facing
##var facing =true  # if true facing to left else facing to rigth
# set from the animation to prevent double playing
#var _playing = false

		
func damage(type: String):
	#print('Damage caused by '+type)
	match type:
		"electricity":
			electrified=true
	
func _physics_process(delta: float) -> void:
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity_sys*delta
	
	#print('Glob.electricBlock is '+str(Glob.electricBlock))	
	if Input.is_action_pressed("Jump") and is_on_floor() :
		if(Glob.electricBlock == false):
			velocity.y =jump_mult*JUMP_VELOCITY
			anim_Sprite2D.play("jump_right")
			#CHECK JUMP action
			'''
			if velocity.x > 0:
				print('JUMp on RIGHT !!')
				anim_Sprite2D.play("jump_right")
			if velocity.x < 0:
				anim_Sprite2D.play("jump_left")
			'''	
	var direction = Input.get_axis("go_left", "go_right") #Input.get_vector("go_left","go_right",null,null)#Input.get_axis("go_left","go_right")
	
	move_and_slide()
	play_walk_animation(direction)
	
	
	if Glob.electricBlock == false:
		if  direction:
			velocity.x =direction*SPEED
		else:
			velocity.x = move_toward(velocity.x,0, SPEED)
			
	else:
		velocity.x = 0.0 
	
func play_walk_animation(direct):
	
	#print('value of direction is: '+str(direct))
	if velocity.x > 0:
		facing = false
		anim_Sprite2D.play("walk_right")
	elif velocity.x < 0:
		facing = true
		anim_Sprite2D.play("walk_left")
	else:
		print('facing to: ',facing)
		if facing:
			anim_Sprite2D.play("idle_left")
		else:
			anim_Sprite2D.play("idle_right")

You are always playing a walk animation every frame, so the jump animation is overridden

mmm, I just defined a flag variable:
var jumping = false
this is going set to True everytime JUMP button is pressed; after I call function: play_walk_animation(direction, jumping).

func play_walk_animation(direct, jump):
	if(jump==false):
		if velocity.x > 0:
			facing = false
			anim_Sprite2D.play("walk_right")
		elif velocity.x < 0:
			facing = true
			anim_Sprite2D.play("walk_left")
		else:
			print('facing to: ',facing)
			if facing:
				anim_Sprite2D.play("idle_left")
			else:
				anim_Sprite2D.play("idle_right")
	else:
		anim_Sprite2D.play("jump_right")

I think that evrytime new update is going to be called, the jumping variable value is set to false…and it doesnt work for me…

Maybe you can use your new jump variable and is_on_floor here?

	var direction = Input.get_axis("go_left", "go_right") 
	
	move_and_slide()
	if jump == false and is_on_floor(): # new condition
		play_walk_animation(direction)