#How to spawn a seperate scene with one node of type `CPUParticles2D` and set its position?

13 messages · Page 1 of 1 (latest)

crisp badger
#

Hi guys,

ok I tried now so many things but I can't figure out how I can spawn one ore many Particle Spawners on a position of my choosing.

I have one scene that just constists of a CPUParticles2D node.
I have setup some nice looking particles and everything looks fine.

In my weapon scene when an area overlaps I want to spawn one of this scene as instance on the location of the object I hit (the enemy).
But no matter what I try it doesn't work.

Here is the code I have so far :

func _on_area_entered(area):
    var particles: CPUParticles2D = particleScene.instantiate() as CPUParticles2D

    particles.global_position = area.global_position
    particles.emitting = true
    add_child(particles)

This will spawn the particles but I can't see them at all.

This works, but they will spawn at the weapon, and not at the enemy i hit:

func _on_area_entered(area):
    var particles: CPUParticles2D = particleScene.instantiate() as CPUParticles2D
    particles.emitting = true
    add_child(particles)

I tried with normal position I tried with position of the parent with all kinds of variation and I also tried the box Local Coords on the Particle Node. Nothing every works.
When I add the particles as child of the object I hit, I get weird behaviour that all particles are cramped up together and form like one bigger particle.

Any ideas how I can implement a sytem that actually works? How can I set the position of a CPUParticles2D node?

Edit: I also found this thread on reddit: https://www.reddit.com/r/godot/comments/zw0xp0/so_particles_can_not_be_emitted_in_relation_to/
Is this really not possible?

Reddit

Explore this post and more from the godot community

mighty tundra
#

Bump

subtle swallow
crisp badger
#

Sorry thats not clear to me, i found a workaround that "kinda" works. Did it like this now:

var dir = global_position.direction_to(area.global_position)
    
    particles.emitting = true
    particles.translate(dir * 2)
subtle swallow
#

set_emission_points take PackedVector2Array which is the same for CollisionsPolygon2D

crisp badger
subtle swallow
#

You can technically have them spawn from hurtboxes

#

collisionpolygons on your enemies

#

emission_points are technically array of vectos2d

crisp badger
#

it's not even like that deep. The problem is just when I set the position of the emitter directly via .position it gives weird behaviour. But now with .translate it works

subtle swallow
#

so you can use hurt_boxes amde of CollisionPolygon2D.polygon

crisp badger
#

because when I set the global_position of the emitter to the global_position of the enemy hit, it should be the same as calculating global_position of player - global_position of enemy (.diretion_to) and then translate the emitter by that amount. In my brain this should be the same, but only with translate does it work

subtle swallow
#

Instead of having these particles emitting from the player/weapon, you can have them be emitted from the enemy.