- Home /
"Filling" an object with fluid
I am working on a game that requires a conical flask to be "filled" with a fluid. However, I'm struggling how to accomplish it. The game is in 3D so a 2D plane is not applicable in this case.
I have tried using a particle system but I don't think I understand the particle system well enough to be able to do what I'm after.
Are there any tutorials that anyone knows of which shows how to "fill" an object internally, like a glass of wine or does anyone know how to do it themselves and are willing to share?
I have found several videos YouTube which show what I'm after, but unfortunately, they have no links on how to do it.
If you take a look at this example, the effect I'm after is the filling of the glass. The pouring of the wine is documented and explained, but I can not for the life of me figure out the all important container filling part.
Any help appreciated, as always.
Answer by tanoshimi · Jan 03, 2015 at 01:30 PM
Real-time fluid dynamics is very complex. There's an interesting research paper (although now over 10 years old) at http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/GDC03.pdf
Why do you need the object to be filled? Just for graphical effect, or does it have some impact on the game logic (i.e. do objects need to float on the water surface?)
Thanks for your response. The reason I need the object filled is that it's what the game is all about. You have to collect a series of "raindrops" in a bucket and fill the conical flask with what you collect in the bucket. I have the conical flask all ready to go but I just can't figure out how to "fill" it. Do you think it might be possible to do this some other way, like using Alpha Cut-off and a texture although I don't see how this can be used in 3D. The flask is purely a gauge but I don't want to switch to 2D as this will change what I plan to do with the game.
Well, if it's just a gauge for graphical effect, you could have a 3d mesh for the liquid which sits inside your conical flask and apply a shader that masks it using the stencil buffer. Then, as you want the beaker to "fill", gradually change the values in the buffer to reveal more of the liquid. This could either be aligned to the base of the flask or, if the flask were tilted, to the world normal ins$$anonymous$$d.
This is one thing I was looking at but I'm a bit unsure how to create my solid "fluid" object (I'm not that clever with 3DS $$anonymous$$ax) and I've not even touched on the shader side of things. Is this the sort of thing you mean?
Yes - that uses an alpha cutoff shader rather than a stencil buffer, but it's essentially the same result. You said you already have the conical flask object, so to create the liquid mesh just shrink that a bit and place it inside the flask.
Tried that with the fluid but the fluid has to be solid and that's where I'm falling down. I can't figure out how to make it solid. I've tried researching but that suggests to use extrude which will take an earth of time! I guess I need to concentrate on one thing before another and maybe I'm trying to do too much too fast. Perhaps I need to make it a 2D game rather than 3D and change how I am going about it.
Answer by Mmmpies · Jan 03, 2015 at 02:07 PM
That video has the source code at the bottom of it although it looks like you have to give them your email address at least to download it.
Really though all you need is some trigger colliders attached to the bottle that can be setActive when pouring. If the collider is hitting the glass then fill the glass.
As @tanoshimi say's full fluid dynamics is really complex but if you just want the glass to fill then that should allow you to spot when the glass is under the stream of liquid.
It get's more complex if the bottle can be rotated though as the trigger colliders could well end up pointing upwards so it depends on the flexibility within your game.
Hi and thanks for your reply. I downloaded the so called "source" and there is no "source" at all. It's basically a document that contains exactly what you see on the web page, unless I missed something.
Ah didn't download it, mainly as I didn't want to hand over my mail, I get enough spam already!
There are already some fluid assets on the store. Depends on your available cash but if it saves you creating your own may well be worth it.
I think there's a free version of fluvio 2 so you can try it out for free.
I know what you mean about spam, but I must admit I haven't had any from them as yet!
I might take a look at Fluvio. I had seen it whilst searching but I thought it was 2D only. Having looked again, they say it's 2D and 3D so I may well give it a shot. I've just had a look at LiquidFun too, but unfortunately, that's 2D only (for now anyway).
Hope it helps but there are some other ones there as well (just search liquid or fluid), a shame you're asking now as I think fluvio was on offer a week or two ago.
I guess you could always use the free version for a while as offers tend to crop up every so often.
Yeah, I'm going to give the free version a shot as I'm currently out of work (hence why I'm creating games). I don't think the 100 emitter limitation will impact on what I need to do and I hope it works in Unity Free too (cheap skate I know...).
Answer by seo_unity · Jan 24, 2018 at 12:30 PM
If you want help, then share your project details at sales@agicent.com. We are a game development company (https://www.agicent.com) and would like to assist you. Cheers :),In case, you are looking for a game development company (https://www.agicent.com), then we can help you. Share your project details at sales@agicent.com and we will assist you for free.