3
\$\begingroup\$

I have around 100 to 200 particles in my game. Then I have 5 to 20 regions (circle-shape) which should count the particles which enter them and add some force to them, so they change their direction.

My idea was now to keep a list of all particles and every region should check the whole list every frame, whether a particle is inside it. For this I calculate the distance between the particle and the central point of the region and check weather its <= the radius of the region.

Is this the most efficient way to do it? Or should every particle have a list of all regions and check whether they are in one of it? Or a totally different approach?

I would like this application to be able to run also on older mobile devices like an iPhone 4S.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

You may want to have each region contain a list of particles which are in it. Then, when you move each particle, check if it is in a new region - add it to the new region's particle list, and remove it from it's current one (based on your checking above). That way you can just tell each region to apply the force to the particles in it's list (the work has already been done for you).

I like this method because it makes the code within the region easier. Useful in case you ever need/want to apply that force the particles more than once, as it will save performance by only having to do the checking once.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .