I'm creating endless runner game. Player doesn't move, floor moves.
I want to make like this : when game starts player is idling animation, but after pressing jump it starts run Thanks for your attention

extends KinematicBody2D

onready var _animated_sprite = $AnimatedSprite

signal died

const GRAVITY = 1500
const JUMP_FORCE = 520

var velocity = Vector2.ZERO
var double_jump = false
var alive = true
var on_ground = false
var game_started = false
var motion = Vector2(0, 1)

func _physics_process(delta):
	if motion.y > 0:
		motion.y += GRAVITY * delta *1.1
	else:
		motion.y += GRAVITY * delta
	jump()
	animation()

func jump():
	if is_on_floor():
		double_jump = false
		if Input.is_action_just_pressed("Jump"):
			motion.y = -JUMP_FORCE
	else:
		if Input.is_action_just_pressed("Jump"):
			if double_jump == false:
				motion.y = -JUMP_FORCE
				double_jump = true
# warning-ignore:integer_division
		if Input.is_action_just_released("Jump") and motion.y < -JUMP_FORCE/2:
# warning-ignore:integer_division
			motion.y = -JUMP_FORCE/2
			
	motion = move_and_slide(motion, Vector2.UP)
	
func animation():
	if is_on_floor():
		on_ground = true
		_animated_sprite.play("Run")
	else:
		on_ground = false
		if motion.y < 0:
			_animated_sprite.play("Jump")

If you play your animation every frame, it will just restart the animation constantly and look like it's not working (stuck on frame 1). You need to have states, like a run state, jump state, etc. so that you only play the animation when switching between states. Usually this would be done with a Finite State Machine, however, if you only have like 3 or 4 states, you can just do it manually and have boolean flags or a string property with the state name,

10 months later