0 votes

So I have attackable grass in my Action RPG like Zelda, and I want to place a sprite of broken grass right after the breaking animation finishes. But the sprite is placed right as the animation plays. I don't know how to make the sprite wait until the animation is done. Here's the script:

extends Node2D

const GrassEffect = preload("res://Effects/GrassEffect/BrokenAttackableGrass.tscn")
const Grass
Pieces = preload("res://Other/GrassPieces.tscn")

func placegrasspieces():
var grassPieces = GrassPieces.instance()
get
parent().addchild(grassPieces)
grassPieces.global
position = global_position

func creategrasseffect():
var grassEffect = GrassEffect.instance()
get
parent().addchild(grassEffect)
grassEffect.global
position = global_position

func onHurtboxareaentered(area):
creategrasseffect()
queuefree()
<-------------------------------- I want to put the "waiting" action here.
place
grass_pieces()

in Engine by (38 points)

1 Answer

0 votes

You can do something after an animation completes by coupling coupling yield with an animation player's animation_finished signal. Generally, that looks like this:

animationPlayer.play("idle")
yield($AnimationPlayer, "animation_finished")
# --- code here executes *after* the running animation finishes...
by (12,290 points)
edited by

Yea, I've seen that done when looking at other posts, but the animation the grass is connected to doesn't have the Animation Player connected, only the animation :/, I'll try this again, but I'm pretty sure I can't use this method.

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.