Particles2d in body entered function

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CB

hello, I wish to show particles “Explosion”, when I destroy na enemy.
in a function body entered.

:bust_in_silhouette: Reply From: p7f

Hi,
There is no problem in doing so. First, get your particles ready (i assume you have that already). Attach the particles as child of the node you want to emmit them. Be sure to unset the emitting property from editor or from code, so the node does not emitt particles all time.

Then, i assume you already connected body_entered signal to a function, let’s call on_Enemy_body_entered(body), or whatever you called that function. Inside it, you check if the enemy died, and if so, you set emitting property of particles to true:

func _on_Enemy_body_entered(body):
    if is_dead:  #here you check if enemy died, idk how you handle that in your code
        $Particles2D.emitting = true

That code was tested in godot 3.1 beta2 and worked. If you are using Godot 3.0.6, it works just calling $Particles2D.restart().

If you share me the code you have till now or the project i can help you further