How Do i Make a 'Breaking Apart' Effect When Meteor is Destroyed?

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

I have meteors that you can destroy by shooting. I want there to be a short breaking apart effect. I made several meteor particle art to make it look like the meteor broke apart, but i don’t know how to actually implement it. My first thought was to have a particles2D that only lasted a second but when i tried it i realized that’s now how particles2D’s work. I could make a new scene for each particle but i wanted to see what you guys think is the most efficient method of making the meteor seem to break apart. Keep in mind that i want them to fade out within a couple seconds, there only needs to be like 3 of them, i want them to rotate and the game is in 2D.

:bust_in_silhouette: Reply From: Diet Estus

You can create a scene called “break_effect.tscn” with the following structure:

Node2D

Sprite1
Sprite2
Sprite3
AnimationPlayer

Use your broken meteor images as the sprites.

Then you can create an animation in which you move the sprites farther apart over time, and even make them increasingly transparent by changing their modulates. You can also rotate them and build this into the animation. Just key frame all these changes into the animation as you make them.

Add a script to the main node and attach the animation finished signal from the animation player. Set this signal up so that when the animation ends, queue_free() is called. This will automatically delete the effect node.

To create this effect in your game, just instance it, position it, and add it to your scene using code. Position it at the meteor that is being destroyed.

That is a good idea, but how will i randomize the sprites? I have 6 different asteroid piece sprites but i only want 3 or 4 of those sprites to be used.w
edit: I figured it out, thank you!

lincolnpepper | 2018-04-24 16:18

You can make a random choice of sprites in the _ready() method of the main Node2D. For example:

_ready();
    var choice = randi() % 5:
    if choice == 0:
          get_node("Sprite1").texture = load("res://meteor_particle0.png")
    elif choice == 1:
          get_node("Sprite1").texture = load("res://meteor_particle1.png")
    elif choice == 2:
            ...

You can do something similar for each Sprite node.

Diet Estus | 2018-04-24 18:18

as i said, i already figured it out. Thanks anyway.

lincolnpepper | 2018-04-24 20:31