+1 vote

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.

in Engine by (243 points)

1 Answer

0 votes
Best answer

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.

by (1,571 points)
selected by

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!

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.

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

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.