0 votes

I tried to get my jumping and falling animations to work but they're always stuck in the first animation frame. Setting it to loop did not work.
Here's the code:

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
const ACLRTE = 80
const MSPEED = 400
const JH = -600
var motion = Vector2()

func _physics_process(delta):

motion.y += GRAVITY
var friction = true

if Input.is_action_pressed("ui_right"):
    $AnimatedSprite.play("move")
    $AnimatedSprite.flip_h = false
    motion.x += ACLRTE
    motion.x = min(motion.x, MSPEED)
elif Input.is_action_pressed("ui_left"):
    $AnimatedSprite.play("move")
    $AnimatedSprite.flip_h = true
    motion.x -= ACLRTE
    motion.x = max(motion.x,  -MSPEED)
else:
    $AnimatedSprite.play("idle")

if is_on_floor():
    if Input.is_action_pressed("ui_select"):
        motion.y = JH
    if friction == true:
        motion.x = lerp(motion.x, 0, 0.05)
else:
    if motion.y < 0:
        $AnimatedSprite.play("jump")
    else:
        $AnimatedSprite.play("fall")

motion = move_and_slide(motion, UP)
pass
A thing I'd like to mention (it probably won't be helpful and or is just normal) is that whenever I quit the debug window, the animation actually changes to the second animation frame.
Godot version 3.3
in Engine by (12 points)
edited by

1 Answer

0 votes

have you tried playing the animation in the editor? maybe the speed is set to slow so the first frames get to run in time.

by (430 points)

When I increased the FPS, it kinda works but the animation is a bit too inconsistent. Like, sometime the animation might play, but other times it won't. So basically, it's not as consistent as I want it to be. It was already set at normal speed when I first asked this question. And plus, my idle and running animations are already working pretty well so I don't get what I'm doing wrong here. Let me know if you have a fix for this.

i would try another method fo on_floor check because the built in is_on_floor() is inconsistent with the move_and_slide() function especially on slopes, also it does seem you aren't applying delta to the motion which might be contributing to the issue and to the overall project. delta is needed to keep a consistent motion across different devices with difeferent fps speeds.

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.