Help Counting Particles - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html) +--- Thread: Help Counting Particles (/thread-715.html) |
Counting Particles - docgonzzo - 13-10-2018 Hi There, I'm working on a 2D game (Unity) about transferring fluid from one cup to another cup. To measure success, I need to count the number of particles that were transferred from the 1st cup to the 2nd cup. Currently, I am subscribing to the Solver.OnCollision event. I have a "Trigger=true" BoxCollider2D inside the 2nd cup that I compare with the event callback Collider. My code is very similar to the code shown in this thread: http://obi.virtualmethodstudio.com/forum/showthread.php?tid=708&highlight=collision My problem is that the "count" is never actually correct. It seems to be always less than the actual count. I'm wondering if there's possibly collisions not being detected? I have my Fixed TimeStep set to 0.005. The transfer can be violent and quick sometimes, but the fluid never clips out of the cup. I'm only using 55 particles. RE: Counting Particles - josemendez - 13-10-2018 (13-10-2018, 03:33 AM)docgonzzo Wrote: Hi There, Hi there, The trigger will not miss collisions. Also, the counting script in that thread takes all particles added during each simulation step into account, so the culprit must be elsewhere. We made some simple tests in 2D with this script, and no collisions are being missed. The FluidFoam sample scene for instance, correctly reports 2500 hits when placing a small cube near the fluid nozzle. My only advice for now would be to make sure your trigger collider is big enough for tunneling (particles jumping over it during consecutive physics steps) to not take place. Let me know if the issue persists. RE: Counting Particles - docgonzzo - 16-10-2018 (13-10-2018, 08:58 AM)josemendez Wrote: Hi there, Thanks so much for the response! Good to know I was barking up the wrong tree In the end, I solved this by destroying (lifespan = 0.0) the particles immediately after their collision callback. Since the 2nd cup isn't transparent it's ok for me to destroy the particles. I also added a 2nd collider on the floor to count and destroy any spillage. The count always comes out to 55 when you add-up what went in the cup and what fell to the floor. But, unforeseen consequence was that I also needed to set the emitter speed to 0 because it would start re-creating the particles after destroying them. Anyway, it works the way I need it to now. Thanks again! RE: Counting Particles - josemendez - 17-10-2018 (16-10-2018, 12:25 AM)docgonzzo Wrote: Thanks so much for the response! Good to know I was barking up the wrong tree Glad you got it working! |