i'm currently trying to make a small platformer game to learn since i'm relatively new to coding and such but i'm having issues with the jump animation.
at first the animation wouldn't even play, the character continuously playing the idle animation in midair. now i managed to get them to actually play the jump animation but it's stuck on the first frame. i've looked at pass qnas and tried the answers from those qnas but it still won't work.
here's my code:
extends KinematicBody2D
var velocity = Vector2(0,0)
const SPEED = 150
const GRAV = 10
const JUMPFORCE = -400
#move please
func _physics_process(delta):
if Input.is_action_pressed("right"):
velocity.x = SPEED
$Sprite.play("walk")
$Sprite.flip_h = false
elif Input.is_action_pressed("left"):
velocity.x = -SPEED
$Sprite.play("walk")
$Sprite.flip_h = true
else:
$Sprite.play("idle")
if not is_on_floor():
$Sprite.play("air")
if Input.is_action_just_pressed("up"):
velocity.y = JUMPFORCE
#gravity
velocity.y = velocity.y + GRAV
#actually getting them to move
velocity = move_and_slide(velocity, Vector2.UP)
velocity.x = lerp(velocity.x, 0, 0.1)
if velocity.y == 0:
velocity.y = 10