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

Question Fill sponge in unity 2d

Discussion in '2D' started by Monkey_M, Dec 14, 2022.

  1. Monkey_M

    Monkey_M

    Joined:
    Mar 10, 2020
    Posts:
    36
    Guys I wish I could fill a rectangular container like a sponge.
    For now I'm doing this:
    - I create a rectangular container
    _I apply colliders to the edges
    _I create very small physical balls
    _with a collision event I prevent the balls that enter the container from leaving.
    Of course I'm using physics to do this.
    What I would like, however, is to give the idea of expansion (see image) which of course I can't use physics. Can anyone advise me how I should go about it?
    water.png
     
  2. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,467
    You could try disabling gravity and rely on the automatic penetration-resolving of the physics engine. Maybe add a weak, random velocity. Also make sure to have some dampening.
     
  3. Monkey_M

    Monkey_M

    Joined:
    Mar 10, 2020
    Posts:
    36
    Thanks for the advice, actually I've already done some tests of this type but I didn't get the desired result. Too weak penetration mixes the particles too much but if I increase it a bit many can no longer penetrate in sponge
     
  4. Monkey_M

    Monkey_M

    Joined:
    Mar 10, 2020
    Posts:
    36
    Any other ideas?
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,992
    would you know any video clip or gif that would show similar effect?
    (just to get some idea how it should look)
     
  6. Monkey_M

    Monkey_M

    Joined:
    Mar 10, 2020
    Posts:
    36
    Last edited: Dec 16, 2022
    mgear likes this.
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,992
    that looks more like flood fill, could try that..

    but maybe needs effect like in those reaction/diffusion models,
    so that it doesn't spread so evenly (like floodfill).

    https://github.com/keijiro/RDSystem