Every animation on my player is playing except Jump and Attack

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

All of my “is pressed” codes work just fine but none of the “is just pressed” codes work. What am i doing wrong? I’m making a 2D platformer
Heres my player code:

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 15
const ACCELERATION = 23
const MAX_SPEED = 125
const JUMP_HEIGHT = -300
var collision_info = move_and_collide(Vector2(0,0))
var motion = Vector2()

func _physics_process(delta):
motion.y += GRAVITY
var friction = false

if Input.is_action_pressed("ui_right"):
	motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
	$Sprite.flip_h = false
	$AnimationPlayer.play("Run")
elif Input.is_action_pressed("ui_left"):
	$Sprite.flip_h = true
	$AnimationPlayer.play("Run")
	motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
else: 
	$AnimationPlayer.play("Idle")
	friction = true



	
if is_on_floor():
	if Input.is_action_just_pressed("ui_up"):
		motion.y = JUMP_HEIGHT
	if friction == true: 
		motion.x = lerp(motion.x, 0, 0.18)
else:
	if motion.y < 0:
		$AnimationPlayer.play("Jump")

if friction == true: 
	motion.x = lerp(motion.x, 0, 0.05)

if Input.is_action_just_pressed("ui_attack"):
	$AnimationPlayer.is_playing("Attack")


motion = move_and_slide(motion, UP)
:bust_in_silhouette: Reply From: nightrobin

It may already played the animation and ended, so you have to loop the animation.

Also, it is better to put the play animation inside the _process or _physics_process and have a variable checker there that is changed depending on the user’s input.

Example:

var isJumping= false

func _ready():
    $AnimationPlayer.get_animation("Jump").set_loop(true)

func _input(delta):
    if Input.is_action_pressed("ui_up"):
        isJumping= true

    if Input.is_action_just_pressed("ui_up"):
        isJumping= false

func _process(delta):
    if isJumping:
         $AnimationPlayer.play("Jump")