I asked a question previously as to why my multi state jump animation wouldn't play and an amazing person told me why it wouldn't work.

I fixed that and the animation will play however the first step of the jump animation the "jumpoff" still won't play it still stays in "idle" until the climax of the jump where it switches into the "jumploop" and then the rest of the multi state animation which works fine.

Could someone try to decipher this for me please?

P.S: sorry if it's obvious I'm rather new to programming

extends KinematicBody2D

var velocity = Vector2(0,0)
const SPEED = 140
const GRAVITY = 35
const JUMPFORCE = -600

func _physics_process(delta):
	
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMPFORCE
	if not is_on_floor():
		velocity.y = velocity.y
		if velocity.y < -200: #going up
			$AnimationPlayer.play("jumpoff")
		elif velocity.y < -10:
			$AnimationPlayer.play("jumploop")
		elif velocity.y > -50 && velocity.y < 10.0: #transition
			$AnimationPlayer.play("landing")
		else: #falling
			$AnimationPlayer.play("fallloop")
	
	if Input.is_action_pressed("right"):
		velocity.x = SPEED
		$Sprite.flip_h = false
		if is_on_floor():
			$AnimationPlayer.play("walk")
	elif Input.is_action_pressed("left"):
		velocity.x = -SPEED
		$Sprite.flip_h = true
		if is_on_floor():
			$AnimationPlayer.play("walk") 
	else:
		if is_on_floor():
			$AnimationPlayer.play("idle")
	
	velocity.y = velocity.y + GRAVITY
	
	velocity = move_and_slide(velocity,Vector2.UP)
	
	velocity.x = lerp(velocity.x,0,0.1)

(Fixed code formatting in OP).

What is probably happening is that the idle animation is being told to play before the jumpoff has a chance to play. What you probably need to do is add a condition so the idle animation cannot play if the user just jumped. Something like this may work (untested):

extends KinematicBody2D

var velocity = Vector2(0,0)
const SPEED = 140
const GRAVITY = 35
const JUMPFORCE = -600

# To track if we are jumping
var is_jumping = false

func _physics_process(delta):
	
	# Change animation based on whether we are on the floor or not
	# before we jump, as is_on_floor only updates AFTER calling
	# move_and_slide, therefore is_on_floor is true even after
	# jump input is pressed (for the first physics frame)
	if not is_on_floor():
		
		# Technically we are just in the air at this point, but
		# we will say we're "jumping" so idle and walk animations
		# do not somehow get called here
		is_jumping = true
		
		velocity.y = velocity.y
		if velocity.y < -200: #going up
			$AnimationPlayer.play("jumpoff")
		elif velocity.y < -10:
			$AnimationPlayer.play("jumploop")
		elif velocity.y > -50 && velocity.y < 10.0: #transition
			$AnimationPlayer.play("landing")
		else: #falling
			$AnimationPlayer.play("fallloop")
	else:
		# If we are on the floor, then we are not jumping!
		is_jumping = false

	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMPFORCE
		# We are jumping!
		is_jumping = true
	
	if Input.is_action_pressed("right"):
		velocity.x = SPEED
		$Sprite.flip_h = false
		
		# Check if we are jumping instead of if we are
		# on the floor
		if not is_jumping:
			$AnimationPlayer.play("walk")
	elif Input.is_action_pressed("left"):
		velocity.x = -SPEED
		$Sprite.flip_h = true
		
		# Same here
		if not is_jumping:
			$AnimationPlayer.play("walk") 
	else:
		# Same here
		if not is_jumping:
			$AnimationPlayer.play("idle")
	
	velocity.y = velocity.y + GRAVITY
	
	velocity = move_and_slide(velocity,Vector2.UP)
	
	velocity.x = lerp(velocity.x,0,0.1)

I think those adjustments should fix the issue :smile:

2 years later