Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Temporarily make fluids in a container ignore other colliders/fluids
#1
Hello,

I'm new to ObiFluid and I'm currently working on a 2D bartender game where you can grab glasses with fluid, move them around and pour the fluids into other glasses (or onto the shelves).

For example, I'd like this to work:
  • Drag and drop the red fluid glass from below through the upper shelf collider and through the blue and green glasses without affecting the liquids at all - it should just pass through it.
  • Rotate the red fluid glass so the red fluid pours out. Once the red fluid has left its glass it should be stopped by any other glass (i.e. fill those glasses and mix with any fluids inside) or the shelf.

So, in short, I'd need a *grabbed glass with liquid* ignore all non-grabbed-glass colliders/liquids, and *liquid that has left a grabbed glass* to normally interact with the world.

Liquids can mix, so I don't think I could do anything like "liquid from the red emitter behaves differently" - it might be glass mixed with red and blue liquid that is grabbed, while other glasses also already have red or blue liquid.

I see two ways this could happen:
  • If I make the simulation 3D with very flat models, it would still look 2D in an orthographic camera and I could use the Z-axis to make a grabbed glass and its contents ignore any other collider. When the fluid leaves the grabbed glass trigger volume because it is poured I could adjust the Z-position of those now-outside-the-glass fluid particles back to the Z-position that everything non-grabbed is on.
  • If there is a way to have multiple simulations and to transfer colliders/fluids between simulations, I could temporary make a grabbed glass and its fluid a separate "grabbed glass" simulation and return any fluid that leaves the grabbed glass to the "main" simulation.

Do those ways sound possible? Is there any other (maybe better?) way to achieve this?


Attached Files
.png   Unity_2024-06-21 16.16.06.023.png (Size: 2.12 KB / Downloads: 16)
Reply
#2
(21-06-2024, 03:31 PM)Tobias Wrote: Hello,

I'm new to ObiFluid and I'm currently working on a 2D bartender game where you can grab glasses with fluid, move them around and pour the fluids into other glasses (or onto the shelves).

For example, I'd like this to work:
  • Drag and drop the red fluid glass from below through the upper shelf collider and through the blue and green glasses without affecting the liquids at all - it should just pass through it.
  • Rotate the red fluid glass so the red fluid pours out. Once the red fluid has left its glass it should be stopped by any other glass (i.e. fill those glasses and mix with any fluids inside) or the shelf.

So, in short, I'd need a *grabbed glass with liquid* ignore all non-grabbed-glass colliders/liquids, and *liquid that has left a grabbed glass* to normally interact with the world.

Liquids can mix, so I don't think I could do anything like "liquid from the red emitter behaves differently" - it might be glass mixed with red and blue liquid that is grabbed, while other glasses also already have red or blue liquid.

I see two ways this could happen:
  • If I make the simulation 3D with very flat models, it would still look 2D in an orthographic camera and I could use the Z-axis to make a grabbed glass and its contents ignore any other collider. When the fluid leaves the grabbed glass trigger volume because it is poured I could adjust the Z-position of those now-outside-the-glass fluid particles back to the Z-position that everything non-grabbed is on.
  • If there is a way to have multiple simulations and to transfer colliders/fluids between simulations, I could temporary make a grabbed glass and its fluid a separate "grabbed glass" simulation and return any fluid that leaves the grabbed glass to the "main" simulation.

Do those ways sound possible? Is there any other (maybe better?) way to achieve this?

Hi!

Either approach should work fine. Note however that colliders are shared among solvers, so in order for the fluid to collide with some colliders but not others you will need to change the fluid/collider collision filters. See “collision filters” here:
https://obi.virtualmethodstudio.com/manu...sions.html

Also check out the bottom of this page, regarding setting collision filters at runtime:
https://obi.virtualmethodstudio.com/manu...sions.html

Kind regards,
Reply
#3
Oh, there are collision filters for particles. Does that mean I could also leave everything in one 2D simulation and make my scenario work by just changing the collision filters for inside-a-grabbed-glass fluid particles (and again when they leave the grabbed glass due to being poured out)? Or is collision between fluids not controlled by collision filters?
Reply
#4
(Yesterday, 06:05 AM)Tobias Wrote: Oh, there are collision filters for particles. Does that mean I could also leave everything in one 2D simulation and make my scenario work by just changing the collision filters for inside-a-grabbed-glass fluid particles (and again when they leave the grabbed glass due to being poured out)? Or is collision between fluids not controlled by collision filters?

Hi Tobias,

No, fluid particles don't collide with each other (as they would behave like solids otherwise). Fluids work by calculating density at each particle's position, doing a weighted sum of the mass of neighboring particles. Then they apply a pressure force proportional to the difference between the measured density and a target density. This doesn't allow for collision filtering to take place.

http://obi.virtualmethodstudio.com/manua...sions.html

Quote:Please note that fluid particles do not collide with each other, only granulars (gravel, pebbles) do. Fluid particles interact with each other trough density constraints, so there will be no contacts between fluid particles reported by the solver. With fluids, you can use advection or diffusion instead to get information about a particle's neighborhood.

You should instead move the emitter to a different solver (you will also need to re-emit active particles and set their positions afterwards), or use a 3D simulation and move fluids in the Z axis.

kind regards,
Reply
#5
(Yesterday, 08:01 AM)josemendez Wrote: You should instead move the emitter to a different solver (you will also need to re-emit active particles and set their positions afterwards)

Can I also move particles between emitters? Since mixing fluids is the point of the game, the glass can contain fluids by multiple emitters, and other particles by those same emitters will be in other glasses.
Reply
#6
(Yesterday, 05:00 PM)Tobias Wrote: Can I also move particles between emitters? Since mixing fluids is the point of the game, the glass can contain fluids by multiple emitters, and other particles by those same emitters will be in other glasses.

Hi,

No, as it generally doesn't make any sense: moving a particle to another emitter would suddenly change all its properties including rest density, mass, size, pressure, etc, potentially breaking the simulation.

Note you don't need to move particles between emitters in order to mix them: fluids from different emitters can interact with each other, and you can use diffusion to smoothly transfer properties between particles belonging to different emitters.

kind regards
Reply
#7
(Yesterday, 05:10 PM)josemendez Wrote: Hi,

No, as it generally doesn't make any sense: moving a particle to another emitter would suddenly change all its properties including rest density, mass, size, pressure, etc, potentially breaking the simulation.

Note you don't need to move particles between emitters in order to mix them: fluids from different emitters can interact with each other, and you can use diffusion to smoothly transfer properties between particles belonging to different emitters.

kind regards

Yes, but in this case I want to be able to have diffusions from the same emitters ignore each other temporarily under certain circumstances. Take the following scenario:
  1. Bottle A contains red liquid from the emitter 1. Bottle B contains blue liquid from emitter 2. Glass C and D are empty.
  2. Into glass C and D I both pour 50% from bottle A and 50% from bottle B. Now both glasses contain mixed liquids from the same emitters.
  3. I now pick up glass C. While I'm moving around glass C, I want it (and its fluid contents) to be able to pass through glass D (and its fluid contents) without any interaction.
I can't just move any emitter to a different solver here. Both glasses contain a bit of fluid by the same emitters.
Reply
#8
(Yesterday, 06:36 PM)Tobias Wrote: Yes, but in this case I want to be able to have diffusions from the same emitters ignore each other temporarily under certain circumstances. Take the following scenario:
  1. Bottle A contains red liquid from the emitter 1. Bottle B contains blue liquid from emitter 2. Glass C and D are empty.
  2. Into glass C and D I both pour 50% from bottle A and 50% from bottle B. Now both glasses contain mixed liquids from the same emitters.
  3. I now pick up glass C. While I'm moving around glass C, I want it (and its fluid contents) to be able to pass through glass D (and its fluid contents) without any interaction.
I can't just move any emitter to a different solver here. Both glasses contain a bit of fluid by the same emitters.

So it's not like each bottle contains fluid from a specific emitter that you can move to a different solver when you want it to stop interacting with other fluids, right?
In that case you will need to do this in 3D and use depth to prevent fluids poured on different containers from interacting with each other.

Currently there's no way to make specific fluid particles ignore other particles when calculating density. We will consider adding something similar to collision filters for density constraints in the future, however it will be considerably more expensive as the amount of neighbors for each fluid particle is high, and the check would need to take place every frame. It's more efficient to use spatial coordinates for this, as spatial binning will automatically make particles that are physically distant  along the Z axis ignore each other without the need to perform any checks.

kind regards,
Reply
#9
Quote:In that case you will need to do this in 3D and use depth to prevent fluids poured on different containers from interacting with each other.

Gotcha. Since I still want it to mostly behave as if it was 2D - what would be the best way to achieve that? 3D colliders with a really small depth? What would be the smallest depth that could still contain particles? Or can I maybe somehow restrict the Z axis for particles until I manually their Z position?

Quote:moving a particle to another emitter would suddenly change all its properties including rest density, mass, size, pressure, etc, potentially breaking the simulation.

I've been thinking a bit about that - are those properties all readable and settable? Could I manually create a copy of an emitter, emit some particles, manually move over particles from the original emitter by setting those properties, and then removing the particles from the old emitter?
Reply