[jMe 1] Create particle on collision

It is my first steps in the particule system.



I have read the article on particule and I see several code in the forum. But each time, it generate particules continuously or a lot of particule in one frame.



What I want to do is to generate one or two particules each time two object collide (collision detection is not a problem) and repeat it over frame. I don't see how to do it "nicely".



I didn't find a method to create only one particle in ParticleMesh. Do I have to create a ParticleMesh for each collision ?  :// If so, it seems to "kill" the jMe particle system.

You will need a pool (or cache) of ParticleMeshes.

If you have for example max. 10 collision at a given time, you need a pool with min. 10 ParticleMeshes.



If a collision happens, you grab an inactive ParticleMesh from the pool, update its location and respawn it.



There is an Example ParticleFactory in the jme 2.0 source.

http://code.google.com/p/jmonkeyengine/source/browse/trunk/src/jmetest/TutorialGuide/ExplosionFactory.java

I don't think having a particlemesh for each collision will kill the particle system, unless you're expecting to have hundreds of collisions at once.



If you mean adding a new mesh every time you detect the collision, ie every frame, then yes that would be a bad idea. What you need is a way of identifying a specific collision across frames, so that you only add an emitter if one isn't there already.



If one is already there then just update it's position.



Then use flow control to control the release rate.



When the objects cease to collide, what I do is stop the emitter from releasing any new particles and start a 'burn out' timer to give the existing ones time to die, before finally removing/recycling the emitter.

Ok thanks.



I understand the basic layout to do it. And I manage to do something (I thinks there is still bugs). I didn't find out how to pause/resume a "spray" emitter though.



Since I expect "a lot of" particles, I create 20 ParticleMesh with 100 particles each. And I keep track of the origine of the collision (the 2 body) for each ParticleMesh to reuse active ParticleMesh or use an inactive one.