Topics: Developer Forum
Jan 20, 2011 at 12:15 AM

Hi all, yes I'm new to Farseer and am probably asking ridiculous questions, but I'm going to ask anyway.

I've created a world, and am using metres as measurement (actually, I'm using pixels but scaling by 100 to 1, so a rectangle of a 100*100 pixels is a metre by metre farseer fixture).

I've created a single screen, bounded by static bodies to contain my dynamic bodies, and want to create particle explosions when a bullet hits the side of the screen, for example.

If I create a 30-50 random rectangles with random rotation and velocity and fire several bullets within a few seconds I get massive lag.  I have about 500 objects at this time.

I appreciate that the particles are probably constrained to a small area of the screen at the time, and causing a lot of work for the solver.

Can I not have the particles added to the collision solver at all?





Jan 20, 2011 at 2:13 AM

I would just draw using XNA's systems and your own velocity and color and such... Without the solver there is no point in having the physics system at all.

Jan 20, 2011 at 2:54 AM

Fair point.

Jan 20, 2011 at 4:43 AM

You can also make all of the particles sensors which will disable the physics system...

Jan 21, 2011 at 5:27 PM

500 dynamic bodies is a lot. Your going to have to decide whether you need the physics engine for particles or not. Sometimes it's better to fake particle effects, but if particles  absolutely need to collide and act realistically you'll need to -

  1. Limit the number of active particles.
  2. Use a Pool to keep allocations and garbage collections to a min.
  3. Setup the particles to not collide with each other.
  4. Use circles instead of squares. Circles create less contacts.
  5. Set FixedRotation to true, this will reduce the number of calculations to process the particle's position greatly.

I hope this helps, at one point we were considering adding a particle shape to the engine. I will talk with the other developers about this and see if it's plausible to add particles into the engine.

Jan 21, 2011 at 11:12 PM

Thanks very much matt,

for now I think I will create a particle object of my own that only involves itself with my "display" world, and not not the farseer physics world, but I will take on board the ideas regarding pooling objects, circles, and fixedrotation.

Thanks for your response and help,