Fluid Counter - 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: Fluid Counter (/thread-3579.html) |
Fluid Counter - 0hsyn1 - 05-09-2022 Hi i am trying to find out the number of particles of water passing through a collider. Emitter produces 400 particulate water. Even if the collider touches all of them, the count remains around 200. http://obi.virtualmethodstudio.com/manual/6.3/scriptingcollisions.html I looked here but I don't understand https://imgur.com/a/if0G3bu PHP Code: ObiSolver solver; RE: Fluid Counter - josemendez - 05-09-2022 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) 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. RE: Fluid Counter - 0hsyn1 - 05-09-2022 (05-09-2022, 01:40 PM)josemendez Wrote: Hi!I was doing silly experiments I added the wrong code I added the wrong code. Sorry counter runs but returns a number greater than 400 particles RE: Fluid Counter - josemendez - 05-09-2022 (05-09-2022, 01:49 PM)0hsyn1 Wrote: I was doing silly experiments I added the wrong code I added the wrong code. Sorry Yes, as I explained this will add one to the counter every frame a particle is in contact with the collider. So unless particles are only in contact for one frame (which is highly unlikely), it will return a number far greater than 400. What you want is to determine if a particle has already been counted and if so, ignore it. There's many ways to do this, easiest is to use a hash set. See: http://obi.virtualmethodstudio.com/forum/showthread.php?tid=708&highlight=collision RE: Fluid Counter - 0hsyn1 - 05-09-2022 (05-09-2022, 01:51 PM)josemendez Wrote: Yes, as I explained this will add one to the counter every frame a particle is in contact with the collider. So unless particles are only in contact for one frame (which is highly unlikely), it will return a number far greater than 400. Yes, I found the post you shared while doing research. "idToCollider" "particle" syntaxes appear as console errors. RE: Fluid Counter - josemendez - 05-09-2022 (05-09-2022, 01:58 PM)0hsyn1 Wrote: Yes, I found the post you shared while doing research. That code was written for Obi 3.5, idToParticle no longer exists. In >3.5 you get the collider like you were already doing in your original code: Code: ObiColliderBase col = world.colliderHandles[contact.bodyB].owner; However the idea of the code is still perfectly valid: use a hash set to determine which particles have already been counted. I've modified your code to work properly: Code: [RequireComponent(typeof(ObiSolver))] RE: Fluid Counter - 0hsyn1 - 05-09-2022 (05-09-2022, 02:06 PM)josemendez Wrote: That code was written for Obi 3.5, idToParticle no longer exists. You get the collider like you were already doing in your original code: works perfectly, thank you very much |