Reputation: 41
I need bottles to be filled with liquid in UNITY 3D. As Unity doesn't have liquids, I need to simulate them. Can you suggest me on how I can achieve these following functionalities with liquid simulation :
3D Object with any shape (Bottle, Conical flask, beaker etc) must be filled with liquid. The volume of liquid to be filled is a variable, which will be decided by the user.
When I tilt/rotate the object, physics must act upon the liquid inside the object as shown in the figure. Liquid inside a bottle and it has to move depending on how the bottle is positioned in 3D.
,
I had tried with Stencil buffers, particle system, Cloth component etc. But couldn't achieve with any of them.
The problem with particle system is that, it is heavy performance and the particles are leaking out from the sharp edges of the GameObject's mesh, even though the Collision is enabled for the particle system. With stencil buffers, I didn't understand how liquid inside a object can move depending upon the positioning of the object.
Any suggestions or solutions are appreciated.
Upvotes: 3
Views: 9320
Reputation: 1
Here are two approaches to simulating a liquid inside a conical flask using Unity:
This approach utilizes a pre-made 3D model of a conical flask and a separate plane to represent the liquid surface.
Conical Flask: Use a standard 3D model of a conical flask. Liquid Plane: Create a flat plane object slightly smaller than the flask's opening. Mesh Deformer: Attach a "Mesh Deformer" component to the liquid plane. This allows you to manipulate the plane's vertices based on external forces. Shader/Material: Create a custom shader or material for the liquid plane that uses a noise texture and animation to simulate the liquid's movement. The noise texture will create a rippling effect, and animation can control the movement direction and intensity. Script: Write a script to control the mesh deformer based on factors like tilting the flask (using gyroscope or keyboard input) or collisions with other objects. The script would adjust the vertex positions of the liquid plane to create a wave-like motion. Benefits:
Relatively simple to set up with basic 3D modeling skills. Good performance for less complex liquid simulations. Limitations:
Doesn't simulate true liquid physics (no splashing, realistic flow). May not be visually convincing for highly detailed simulations. 2. Particle Systems:
This approach utilizes Unity's built-in particle system to represent the liquid.
Particle System: Create a particle system within the conical flask. Choose a pre-made particle system preset like "Mist" or "Water Fountain" as a starting point. Particle Properties: Adjust the particle system properties like size, color, and movement direction to resemble a liquid. You can use a gradient to create a color transition from the bottom (darker) to the top (lighter) of the liquid. Collision Detection: Enable collision detection for the particles with the flask walls. This will cause the particles to bounce off the walls and create a more realistic flow behavior. Script (Optional): A script can be used to add additional functionalities like controlling the particle system's emission rate based on the tilt of the flask or adding forces to simulate swirling motion. Benefits:
More visually appealing liquid simulation with splashing and flow effects. Can be optimized for performance with careful particle system configuration. Limitations:
Requires more tweaking and experimentation to achieve a realistic look. Can be more computationally expensive compared to the mesh deformer approach.
Upvotes: -1
Reputation: 46
There is good assest on the assets store. For GPU based Fluid Simulation.
https://www.assetstore.unity3d.com/en/#!/content/65359
You can give it a shot.
Upvotes: 1