0 votes

I'm working a bit on an FPS game in Godot 3.

I've made a gun shooting laser projectiles.

I want the laser projectiles to leave a particle trail behind them.

The problem is - when the projectile hits a target, I need to remove the projectile, but keep the particle tray around until all particles have dissolved.

What I have now is queue_free() in the script whenever the projectile hits - which works but the trail disappears awkwardly, instead of naturally fading out.

I've tried using an AnimationPlayer to call queue_free() on my Projectile's root node, after a short delay - but that crashes the game after I fire a few shots.

How should I approach this?

asked Feb 12, 2019 in Engine by unfa (156 points)

Maybe append a hash with a ref to the node and a "killtime" to an array. (Or use two arrays).
Then use a timer (increases a global count) which periodically checks the kill timer count of the first array entry, then does a queue
free on that item and removes it with pop_front.

2 Answers

+1 vote
Best answer

Make the head of the projectile invisible or play some explosion animation, disable its collisions, then wait for some time, long enough for the trail to fade, using a timer, a GDScript counter or an animation player. Then, use queue_free at the very end.

Another way is to split up the trail on impact so you can free the main part of the projectile, while the trail will be allowed to live a bit longer with a timeout before it gets freed.

answered Feb 12, 2019 by Zylann (22,045 points)
selected Feb 13, 2019 by unfa

I have decided to spawn a "Hit" scene and reparent my patrticle trail node to that scene on impact, immediately before running queue_free() on the projectile scene - works great!

I use this answer:
https://godotengine.org/qa/9806/reparent-node-at-runtime

+1 vote

I've tried using an AnimationPlayer to call queue_free() on my Projectile's root node, after a short delay - but that crashes the game after I fire a few shots.

I haven't tried the method you mentioned myself, but try connecting the AnimationPlayer's animation_finished signal to a function that calls queue_free() instead. Just make sure the animation is long enough so that all particles have enough time to fade entirely.

answered Feb 12, 2019 by Calinou (4,533 points)

Turns out - my game was crashing because my "Projectile" scene was spawning "Hit" scenes every frame after colliding with anything - that caused the game to crash after a few seconds. Once I fixed this - it no longer crashes the game!

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.