0 votes

I have a fireball that should switch to a new explode animation upon contact with a physics body. Is there a way to play an animation using the body_entered function?

I would have figured with the below code the fireball would just pass through objects and play the new animation?

I've tested queue_free and the fireball correctly interacts with bodies and gets removed from memory, but I can't get the animation to change.

func _on_Fireball_body_entered(body):
    # queue_free()
asked Apr 1 in Engine by muffinchin (12 points)

2 Answers

+1 vote

If you call queue_free() right after you start your new animation, the animation won't show because your fireball will be removed pretty much instantly. Keep in mind that while queue_free() does not immediately delete an object, it will be deleted in the next frame, so at 60 fps it will be gone in about 16.6 milliseconds.

You could do something like

func _on_Fireball_body_entered(body):
    yield($AnimatedSprite, "animation_finished")

This will pause the body entered function until the animation has finished (signal animation_finished is emitted by AnimatedSprite and then free the fireball (the code above is untested, but you get the idea :) ).

For more info on yield, see the docs.

answered Apr 1 by omggomb (691 points)
0 votes

podrías probar con esto

func _on_Fireball_body_entered(body): 
    if body == player:
    $AnimatedSprite.playing = true
func _on_timer_timeout():

ajustando en tiempo según cuando acabe la animación

answered May 7 by Gat5lol (14 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.