+3 votes

I would like to have particles, which fly around and if they enter a certain region a force should be added to them and I would also like to count the amount of particles, which entered a certain region.

I tried it with Particles2D and ParticlesAttractor2D, but it is not possible to count the particles with them.

So what is the most efficient way to do this? I would like it to run on mobile devices and also a little bit older ones.

Should I use Area2D and KinematicBodys or implement everything myself? If so how should I do it?

in Engine by (105 points)

1 Answer

+3 votes
Best answer

Look at the Bullet Shower demo if you want an efficient solution. But if you want to use a lot of collision shapes, there is a setting in Project Settings > Physics 2D > cell_size. It should always be a a number equal to 2^n and increasing it improves performance with a lot of large collision shapes, and decreasing it helps with small collision shapes. More info is in the 2D physics doc.

by (846 points)
selected by

Thank you so much batman :) Just one question, how could I test if one implementation is better than another one? I mean what if I don't see a difference on my mobile device? Is there any way I could compare/benchmark both implementations/approaches?

What I usually do is just add a label and set it's text to OS.get_frames_per_second() to see the FPS.

Thanks a good idea! :) But it's always at 60. Why don't I get more than 60?

Because what if both implementations are at 60 FPS. Which is better then?

The more advanced solution (that I haven't tried myself yet) is to use the debugger while the game is running. Look at the performance tab and pick the implementation with the lowest Process or Fixed Process time (depending on which of the two you used). Also, you can see how they scale by stress testing them by simply adding more and more objects.

Turn off Vsync to uncap the FPS

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.