- Edited
I have problem with Jump and Fall animations, it only plays the next frames if I'm going somewhere. How to fix it?
extends KinematicBody2D
var velocity = Vector2()
const GRV = 20
const J = -350
const F = Vector2(0, -1)
var WAY = false
func _physics_process(_delta):
if Input.is_action_pressed("ui_right"):
velocity.x = 250
elif Input.is_action_pressed("ui_left"):
velocity.x = -250
else:
velocity.x = 0
if Input.is_action_pressed("ui_up"):
if WAY == true:
velocity.y = J
WAY = false
if is_on_floor():
WAY = true
else:
WAY = false
velocity.y += GRV
velocity = move_and_slide(velocity, F)
# warning-ignore:unused_argument
func _process(delta):
if Input.is_action_pressed("ui_right"):
if WAY == true:
$AnimatedSprite.play("Run")
elif Input.is_action_pressed("ui_left"):
if WAY == true:
$AnimatedSprite.play("Run")
else:
$AnimatedSprite.play("Idle")
if velocity.y < -10:
$AnimatedSprite.play("Jump")
if velocity.y > 10:
$AnimatedSprite.play("Fall")
if Input.is_action_pressed("ui_right"):
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
$AnimatedSprite.flip_h = true