Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Counting Particles
#1
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...=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.
Reply
#2
(13-10-2018, 03:33 AM)docgonzzo Wrote: 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...=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.

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.
Reply
#3
(13-10-2018, 08:58 AM)josemendez Wrote: 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.

Thanks so much for the response! Good to know I was barking up the wrong tree Sonrisa

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!
Reply
#4
(16-10-2018, 12:25 AM)docgonzzo Wrote: Thanks so much for the response! Good to know I was barking up the wrong tree Sonrisa

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!

Glad you got it working! Sonrisa
Reply