how to make my animation work

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

i have this part of my code :

 if input_vector.x == 0:
	apply_friction()
	animplay.animation = "idle"

else:
	apply_accel(input_vector.x) 
	animplay.animation = "run"
	
	if input_vector.x > 0:
		animplay.flip_h = false
	elif input_vector.x < 0:
		animplay.flip_h = true
	
if is_on_floor():
	if Input.is_action_pressed("up"):
		vel.y = jump_height
else:
	animplay.play("anim_jump")
	if Input.is_action_just_released("up") and vel.y < jump_release:
		vel.y = jump_release

the problem is the animation for the jump doesn’t want to work, there is just the 1st frame working, and if i want to change :

    animplay.play("anim_jump")

into :

    animplay.animation = "anim_jump"

the others animations will not work properly, they will also play only the 1st frame of their animations

:bust_in_silhouette: Reply From: Cire_arievilo1

Try:

Func set_animation():
    if input_vector.x != 0:
       animplay.play("run")
   elif vel.y != 0:
       animplay.play("anim_jump")
   else:
       animplay.play("idle")

put this function inside your process function.

this code has not been tested, so it may be wrong

sorry for the late response, i had to stop programming for a while.
I had to rewrite your code for me to work.

if input_vector.x != 0 and is_on_floor():
		animplay.play("run")
elif vel.y != 0:
	if Input.is_action_pressed("up"):
		animplay.play("jump")
	if Input.is_action_just_released("up"):
		animplay.animation = "jump"
		animplay.frame = 6

and i decided to change a little the beginnning of the old code i gave here.(your code is in the end)

if input_vector.x == 0:
	apply_friction()

else: 
	
	apply_accel(input_vector.x) 
	
	if input_vector.x < 0:
		animplay.flip_h = true
	elif input_vector.x > 0:
		animplay.flip_h = false

if is_on_floor():
	if Input.is_action_pressed("up"):
		vel.y = jump_force
else:
	if Input.is_action_just_released("up") and vel.y < jump_release:
		vel.y = jump_release
		
	if vel.y > 0:
		vel.y += additional_fall_gravity
		
var was_in_air = not is_on_floor() 
		
vel = move_and_slide(vel, Vector2.UP)


if input_vector.x != 0 and is_on_floor():
		animplay.play("run")
elif vel.y != 0:
	if Input.is_action_pressed("up"):
		animplay.play("jump")
	if Input.is_action_just_released("up"):
		animplay.animation = "jump"
		animplay.frame = 6
else:
	animplay.play("idle")

i can clearly say that my code has no sense, and is very painful to read lol, but in the end it worked, so thnks for your help.

cehef | 2022-11-27 03:31