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")
asked 6 days ago in Engine by skylabelmho (23 points)

1 Answer

+1 vote
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
answered 5 days ago by Brinux (287 points)
selected 5 days ago by skylabelmho

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.