0 votes
extends KinematicBody2D

const GRAVITY = 50
const JUMP_FORCE = -1100
const SPEED = 200
const UP = Vector2.UP

var velocity = Vector2()
var facingleft = false
var facing
right = true

func physicsprocess(delta):
velocity.y += GRAVITY

if Input.is_action_pressed("move_left"):
    facing_left = true
    facing_right = false
    velocity.x = -SPEED
elif Input.is_action_pressed("move_right"):
    facing_left = false
    facing_right = true
    velocity.x = SPEED
    velocity.x = 0
    if facing_left:
    elif facing_right:

if Input.is_action_just_pressed("jump") and is_on_floor():
    velocity.y = JUMP_FORCE
    if facing_left:
    elif facing_right:

velocity = move_and_slide(velocity, UP)
Godot version 3.4.4
in Engine by (28 points)

Try adding some debug print()'s after each animation play just sp you know if it's even being called or not.

It is being called, but the animation is not playing, it looks like it appears for only a split second and then immediately changes to running or idle animation.

1 Answer

+1 vote

This seems to be a classic beginner mistake:

Your jump animation should start properly. However, the very next frame the first section of your movement code will most likely get into its else portion, where you'll set idle_left or idle_right, overwriting your jump.

You'll need an extra boolean variable (or some other variable representing your character's current state) so your movement code doesn't set a move or idle animation while you're jumping.

by (234 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.