Particle trail for a 3D projectile - how to leave it behind after removing the projectile?

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

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?

Maybe append a hash with a ref to the node and a “kill_time” 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.

wombatstampede | 2019-02-12 14:08

:bust_in_silhouette: Reply From: Calinou

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.

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!

unfa | 2019-02-13 01:55

:bust_in_silhouette: Reply From: Zylann

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.

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://forum.godotengine.org/9806/reparent-node-at-runtime

unfa | 2019-02-13 01:54