Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fluid Counter
#2
Hi!

Your code doesn't make much sense: it iterates trough all contacts, and for all contacts against a collider in layer 7 (which I assume is the white cube in your image) it sets counter = solver.contactCount. So all your code is equivalent to just:

Code:
counter = solver.contactCount

Which is the current amount of contacts in the solver, not the amount of particles that have ever been in touch with the white cube.

Probably what you want is to just count the contacts, by increasing the counter by one each time you find a contact between a particle and the collider:
Code:
void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
     {
         var world = ObiColliderWorld.GetInstance();

         // just iterate over all contacts in the current frame:
         foreach (Oni.Contact contact in e.contacts)
         {
             // if this one is an actual collision:
             if (contact.distance < 0.01)
             {
                 ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
                 if (col != null && col.gameObject.layer == 7)
                 {
                     counter++;
                 }
             }
         }

}

Note this will only work if particles are in contact against the cube for a single frame, which is a rather restrictive assumption. You probably want to store particle indices in a hash set, to determine if a specific particle has already been counted and in that case, ignore it.
Reply


Messages In This Thread
Fluid Counter - by 0hsyn1 - 05-09-2022, 01:04 PM
RE: Fluid Counter - by josemendez - 05-09-2022, 01:40 PM
RE: Fluid Counter - by 0hsyn1 - 05-09-2022, 01:49 PM
RE: Fluid Counter - by josemendez - 05-09-2022, 01:51 PM
RE: Fluid Counter - by 0hsyn1 - 05-09-2022, 01:58 PM
RE: Fluid Counter - by josemendez - 05-09-2022, 02:06 PM
RE: Fluid Counter - by 0hsyn1 - 05-09-2022, 02:10 PM