How do I set particles to emit through a script

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

Hello. I am new to the godot engine and I am trying to set the particles to emit when the player enters the body of the enemy. This is my code:

func _on_Area2D_body_entered(body):
    Health -= 20

    if == "Player" or == "PlayerCollider" or == "PlayerArena":
	explosion.emitting = true
	if explosion.emitting == false:

And the part where I loaded the ‘explosion’ scene is:

var explosion = load("res://Particles.tscn").instance()

What am I doing wrong and why is the particle not emitting when the player goes into the enemy?


We’re going to have to see more of the setup here. From what I can tell, the scene for the particles/explosion should be preloaded so as to save on performance. When it’s time, the explosion should be instanced, then added as a child, then moved into place, then setup (i.e. explosion.emitting = true), and finally animated. Once the explosion animation is finished, the scene should be removed (i.e. use queue_free()).

Ertain | 2021-08-15 17:48