Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2D Fluid inside Container mechanics

Discussion in 'Physics' started by yousseffotouh2013, Nov 17, 2020.

  1. yousseffotouh2013

    yousseffotouh2013

    Joined:
    May 11, 2019
    Posts:
    5
    I'm having trouble maintaining fluid stability inside a container.

    For example , I'm using this asset to simulate fluid mechanics : https://assetstore.unity.com/packages/tools/particles-effects/water-2d-136297

    However , in my game I'm trying to place the liquid in a moving container in which i want this liquid to respond properly with physics of the moving container.

    The major problem I'm facing is that when the container moves fast , the liquid starts to penetrate or spill outside the container , although i have set the proper colliders and rigid bodies.

    I'm not sure why this is occurring in the first place , but i have tried to change some properties of the rigid bodies but with no use (for example making the collision detection continuous instead of discrete).

    This is the video where I'm displaying the issue : https://drive.google.com/file/d/1m_Bxio0ioCEOmZ2qlxlYXTCS3SifxraX/view?usp=sharing

    A free fall example also :
    https://drive.google.com/file/d/1d3-ZsN1InARYFECBjy8MLgmDLv1_sgxN/view?usp=sharing

    How would I enhance this ?
     
    Last edited: Nov 17, 2020
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,533
    I would suggest you ask the owner of that asset store item unless somehow here has already used this asset.
     
  3. rubcc95

    rubcc95

    Joined:
    Dec 27, 2019
    Posts:
    222
    Well, it's not the asset itself. When you move rapidly a gameobject its rigidbody2d should have collision detection mode continuos in order to ensure all collision posibilities between frames. If not, gameobject could teleport though colliders without triggering nothing.

    1st of all, go to Water2D/Prefab/WaterDrop (OilDrop if youre using oil) or to your custom Metaball Particle if you created another material. On the prefab rigidbody, change collision detection to continuous. Remember this will make a performance drop, since it needs more cycles.

    Next, your platform kinematic rigidbody should also have collsion detection mode continuos. In game you should never change your transform.position value. Instead of it, use rigidbody2D.MovePosition() at fixedUpdate.
    Finally, remember the error will persist if you move your plattform directly through inspector, like at the video... since it still moves your transform.position, but it will work during game.
     

    Attached Files:

  4. ammarrao115

    ammarrao115

    Joined:
    Aug 11, 2019
    Posts:
    1
    Hi. Its quite late to reply. Maybe someone else will found it useful.
    Try to change the Rigidbodies setting like Collision Detection from discrete to continuous.
    Moreover, try changing interpolation from none to extrapolate or interpolate.
    Hopefully It will help.