How to get my jump and fall animations to actually play?

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

I tried to get my jumping and falling animations to work but they’re always stuck in the first animation frame. Setting it to loop did not work.
Here’s the code:

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
const ACLRTE = 80
const MSPEED = 400
const JH = -600
var motion = Vector2()

func _physics_process(delta):

motion.y += GRAVITY
var friction = true

if Input.is_action_pressed("ui_right"):
	$AnimatedSprite.flip_h = false
	motion.x += ACLRTE
	motion.x = min(motion.x, MSPEED)
elif Input.is_action_pressed("ui_left"):
	$AnimatedSprite.flip_h = true
	motion.x -= ACLRTE
	motion.x = max(motion.x,  -MSPEED)

if is_on_floor():
	if Input.is_action_pressed("ui_select"):
		motion.y = JH
	if friction == true:
		motion.x = lerp(motion.x, 0, 0.05)
	if motion.y < 0:

motion = move_and_slide(motion, UP)
A thing I'd like to mention (it probably won't be helpful and or is just normal) is that whenever I quit the debug window, the animation actually changes to the second animation frame.
:bust_in_silhouette: Reply From: vnmk8

have you tried playing the animation in the editor? maybe the speed is set to slow so the first frames get to run in time.

When I increased the FPS, it kinda works but the animation is a bit too inconsistent. Like, sometime the animation might play, but other times it won’t. So basically, it’s not as consistent as I want it to be. It was already set at normal speed when I first asked this question. And plus, my idle and running animations are already working pretty well so I don’t get what I’m doing wrong here. Let me know if you have a fix for this.

sackydzNG | 2021-07-31 15:49

i would try another method fo on_floor check because the built in is_on_floor() is inconsistent with the move_and_slide() function especially on slopes, also it does seem you aren’t applying delta to the motion which might be contributing to the issue and to the overall project. delta is needed to keep a consistent motion across different devices with difeferent fps speeds.

vnmk8 | 2021-07-31 20:32