Collision with Particles?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Yugo
:warning: Old Version Published before Godot 3 was released.

I have a Particles2D object which emits particles and a ParticleAttractor2D Object which attracts them. I would like to count how many Particles entered the ParticleAttractor.

So how could I do this?
I tried it with Area2D, but it didn’t recognize them.

I don’t think it’s possible to detect collision with particles… I may be wrong though…

La_Blazer | 2016-03-03 21:29

:bust_in_silhouette: Reply From: lukas

It is not possible at the moment. Only way is to make your own “particle system”. Be careful if you will implement particle as rigidbody because it can consume a noticeable amount of CPU power. If you only want to count number of particles entered to attractor, you need not to use rigidbodies.

How should I implement them in the most efficent way?
I think I will use an Area2D instead of an ParticleAttractor.

Yugo | 2016-03-05 12:55

Not sure :). If you use Area2D as particle attractor (and set it as gravity point) your particles need to be rigid bodies (you can also have collisions between each other). Big amount of particles can decrease performance of your game, especially if you are making a mobile game.
Second option is to make everything manually. Particle will be sprite. Attractor will be eg. Position2D with export variable radius. “Particle” behavior of this system will need to be programmed in GDScript.

lukas | 2016-03-05 13:04

That’s a good idea, thank you Lukas :slight_smile:

Just one question: If I make my own Attractor with for example a Position2D, it would need to check in the _process(delta) in an endless lop every frame for collisions right? Isn’t this bad for the performance? Or is this the only way? And yeah I would like to make it a mobile game.

Yugo | 2016-03-05 13:25

Yes, the state of each particle need to be checked in _process(delta) or _fixed_process(delta) (maybe someone will have better idea how to do this). To be honest I don’t know how badly it can affect performance (GDScript indeed isn’t the fastest languge). I played for a while with rigid bodies and on my phone I experienced noticeable decrease of FPS when I increased their number. If I remember it correctly more than 30 (with collision detection turn on) was a performance killer on my phone (but maybe I made something wrong). So my guess is that particle as sprite with its functionality written in GDScript will perform better. (but note it is just a guess based on my experience and maybe I am wrong)

lukas | 2016-03-05 13:45

Thank you very much I will try it :slight_smile:

Yugo | 2016-03-07 00:13