Stacking multiple gpuparticles

I’m trying to have it where when a gun fires it emits some gun smoke using GPUparticles2D, however the GPUparticles2D node has to wait for the old some to reach the end of their life time before emitting more particles. Also the gun doesn’t emit more smoke even when held down and auto-fires.

Some messy code:
If Input.is_action_pressed (“Primary Shoot”) and can_fire:
var bullet_instance = bullet. instantiate()
bullet_instance.rotation = rotation
bullet_instance-global_position =$Position2D.global_position
If flip_v == false:
position.x = lerp(position.x, get_parent().position.x-3, 0.5)
Else:
position.x = lerp(position.x, get_parent().position.x+3, 0.5)
$GPUParticles2D.emitting = true
get_parent().add_child(bullet_instance)
can_fire = false
await get_tree.create_timer(PlayerAutoload.Fire_rate).timeout
can_fire = true

I am not sure this it true. Just call stop on it and set it emitting again.

Here I think you need to emit when a bullet is fired, and if the key is still pressed another bullet is fired, so you would stop the particles, then start emitting them again. Any existing smoke particles will continue on their life cycle.

If you have your settings set to explosive with randomness in their upward direction and a fair lifetime, say, rising up, on multiple shots you could build up quite a bit of smoke depending on your fire rate.

Change:

$GPUParticles2D.emitting = true

To

$GPUParticles2D.emitting = false #stops it if it is still emitting first
$GPUParticles2D.emitting = true # restarts it again

There are tons of settings but I would also set it the particles to one shot for the smoke.

I tried this and it still produces the same results, I have one_shot turned on, and the time frame in between emissions is 0.3 seconds

you will need to call .restart() before .emitting = true

It emits particles the way I want, though the particles from the previous shot get deleted before reaching the end of their lifetime

then you just need to add a new gpuparticle2d node instead of emitting the same particle

Can you explain further?

duplicate this node:

var new_particle = $GPUParticles2D.duplicate()
add_child(new_particle)
new_particle.restart()
new_particle.emitting = true
new_particle.finished.connect(func(): 
	remove_child(new_particle)
	new_particle.queue_free())
1 Like

Tysm, it work great

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.