0 votes

My character has an animation when gravity affects him ("speed.y > 0"). but before I touch the ground, I want to press the down key in the air so that when I get to the ground, the sitting animation is done, but this animation does not happen, on the contrary the animation of when the gravity affects it is frozen.

thats my scrips:

func _move(delta):
if velocidad.y > 0:
    $AnimatedSprite.play("Caer")
if is_on_floor():
   if Input.is_action_just_pressed("ui_down"):
        $AnimatedSprite.play("Sentandose")
        yield ($AnimatedSprite, "animation_finished")
        $AnimatedSprite.play("Sentado")
in Engine by (28 points)

1 Answer

+2 votes
Best answer

Perhaps instead of calling a false keypress, a better way would be to let the animation play by tracking the 'in air' state of your player. Maybe like this:

var was_in_air == false #previous frame in-air state
var in_air == false  #current frame in-air state

func _move(delta):
    if velocidad.y > 0:
        $AnimatedSprite.play("Caer")
        in_air = true
func is_on_floor():
    if was_in_air == false && in_air == true:  #will only trigger once
        $AnimatedSprite.play("Sentandose")
        yield ($AnimatedSprite, "animation_finished")
        $AnimatedSprite.play("Sentado")
        in_air = false
was_in_air = in_air
by (328 points)
selected by

thank you so mucho my friend <3

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.