Obi Official Forum

Full Version: Deleting particles when in contact with certain objects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

Context:
I am relatively new to unity and very new to Obi Fluids. I am working on a VR project where I have an emitter for a sink that turns on if the player holds a cup under the sink. This part works fine, but because I want the particles to stay in the cup, I have set the lifespan to "infinity" for my sink emitter. This works fine when the water is in the cup, but because movement is very jumpy/sudden in VR, sometimes the particles will fly out of the cup and into the sink / on the floor.

Question:
Is there a way to make it so particles are killed (lifespan set to 0) if they touch the sink or floor (or any specific object) and still have an infinite life in the cup? The goal is to have an infinite life for the particles only while in the cup, and if the particles hit the sink or floor they are sent back to the emitter. This would mean I could theoretically fill up my cup, dump it down the sink and see the particles "drain", and fill my cup at the sink again.

Let me know if I can clarify anything. As mentioned, I'm relatively new to this, so I don't have any foundation work for this goal; I'm starting from scratch. I mostly want to know if it's possible and what I would need to do to make this happen (e.g. call a system or built in function that I am unaware of.)

Thanks!
Hi there!

You want to use collision callbacks:
http://obi.virtualmethodstudio.com/manua...sions.html

Then, just set the lifetime of the particles in contact with your collider to zero. Like this:

Code:
int particleIndex = solver.simplices[contact.bodyA];
ObiSolver.ParticleInActor pa = solver.particleToActor[particleIndex];
(pa.actor as ObiEmitter).life[pa.indexInActor] = 0;

The manual includes sample code snippets to iterate trough all contacts and determine particles in contact with a given collider, as well as killing a certain particle in a emitter - like above.

let me know if you need further help, kind regards
That seems to be working great, Thanks for the help!