Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help How detect amount of fluid in a container
#1
Hello,

I am trying to create a cooking game where you can blender fruits and pour the juice into a container. For the game, I need to detect if a container was fill and how much liquid was in it.  I also need to be able to distinguish between different types of liquid like apple juice or orange juice to make sure the correct liquid is in it. What would be a good way to do this? 

Thank you
Reply
#2
(16-10-2019, 08:46 PM)Immersive_Matt Wrote: Hello,

I am trying to create a cooking game where you can blender fruits and pour the juice into a container. For the game, I need to detect if a container was fill and how much liquid was in it.  I also need to be able to distinguish between different types of liquid like apple juice or orange juice to make sure the correct liquid is in it. What would be a good way to do this? 

Thank you

Hi,

Subscribe to contact callbacks to detect particles inside a trigger collider. See:
http://obi.virtualmethodstudio.com/tutor...sions.html
Reply
#3
Thank you! This is sort of a separate question, but how would I then detect if different particles of different actors on in a container?
Reply
#4
(17-10-2019, 04:13 PM)Immersive_Matt Wrote: Thank you! This is sort of a separate question, but how would I then detect if different particles of different actors on in a container?

See the "Retrieving the actor involved in a contact" section in the link I provided Sonrisa.
Reply
#5
(17-10-2019, 07:02 AM)josemendez Wrote: Hi,

Subscribe to contact callbacks to detect particles inside a trigger collider. See:
http://obi.virtualmethodstudio.com/tutor...sions.html

Hi there,

Since this awesome asset is new to me, I'm still learning its depth therefore I kindly ask you to bear with me as I'm just going to let my thoughts out...

Is there any option to subscribe only to a specific collision layer, i.e. "Bucket" ? - or is there any "collision matrix" like the Unity's "Layer Collision Matrix"? 
... as per the documentation under "Scripting Collisions" I'm receiving all the particle contacts/collisions and having to call :

Code:
foreach (Oni.Contact contact in currentContacts)
{
    Component coll;
    if (ObiCollider.idToCollider.TryGetValue(contact.other, out coll))
    {
        if (coll.gameObject.layer != 11) // Layer I want to check against
            continue;

        // ... Rest of the code ...
    }
}

And with 1000 particles I get approximately 10-15k iterations which seems a bit of overkill.

Am I missing something or this is the only way to do it?
Reply
#6
(15-01-2020, 10:07 AM)N0Skillz Wrote: Hi there,

Since this awesome asset is new to me, I'm still learning its depth therefore I kindly ask you to bear with me as I'm just going to let my thoughts out...

Is there any option to subscribe only to a specific collision layer, i.e. "Bucket" ? - or is there any "collision matrix" like the Unity's "Layer Collision Matrix"? 
... as per the documentation under "Scripting Collisions" I'm receiving all the particle contacts/collisions and having to call :

Code:
foreach (Oni.Contact contact in currentContacts)
{
   Component coll;
   if (ObiCollider.idToCollider.TryGetValue(contact.other, out coll))
   {
       if (coll.gameObject.layer != 11) // Layer I want to check against
           continue;

       // ... Rest of the code ...
   }
}

And with 1000 particles I get approximately 10-15k iterations which seems a bit of overkill.

Am I missing something or this is the only way to do it?

Hi,

It depends on how many colliders you have, and how large their bounding box is. When a particle enters the bounding box of a collider, it generates a speculative contact. It is not uncommon for the engine to process 40-80k contacts per frame in scenes with many particles/colliders. That's the reason we cannot use Unity's vanilla collision callbacks, as under the hood Obi is pretty much DOTS in disguise and works with massive amounts of data.

The issue is iterating trough them in C# in a single thread. For a large enough amount of contacts, I'd use jobs/threads to process them in parallel.

You can use phases to filter out collisions between particles and colliders, similar to Unity's collision matrix/layers. See:
http://obi.virtualmethodstudio.com/tutor...sions.html
Reply