Search Unity

Create dynamic sand in rooms

Discussion in 'World Building' started by Ambrose998800, Nov 24, 2018.

  1. Ambrose998800

    Ambrose998800

    Joined:
    Jun 23, 2015
    Posts:
    74
    Hi there.

    I have a room in a city with random sandstorms coming in. What I want to do, is if the player leaves a room open after exploring, the sandstorm will fill that room with sand. That should happen dynamically; means, after the first storm, there is just a little bit of sand in the corners. After the second, the sand fills the corners and the floor edges, and so on.

    The target is, that it looks natural (most sand in the corners, much along the walls, less in the center of the room and in the places the sand can creep away).



    I already made a system to find the corners and edges in the room and place stuff there, but I have no idea how to create the sand itself. What could work? Using prefabs for all possibilities? Or is there a way to generate layers of meshes at certain points at runtime? Cool would be if I could 'clamp' a kind of veneer at several points in the room and let that define the sand surface...

    Any ideas? Greetings
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    You could try creating a blendshape animation of the sand piling up and when ingame move a mesh collider that conforms to the sand shape up in relation to the sand height.
     
  3. Ambrose998800

    Ambrose998800

    Joined:
    Jun 23, 2015
    Posts:
    74
    Blendshape animation pushed by a moving collider. Not bad, but how should I form the meshcollider dynamically?

    What I tried now was clamping up a plane with the cloth simulator on it. The result isn't that bad. May there be a way to simulate that offscreen and bake a mesh out of it? I mean a static mesh in the current shape...

     
  4. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    I made a simple example, maybe that's enough for your needs (adjust the 'SandFill' variable on the SandRoom object in the SampleScene to see the effect)
     

    Attached Files:

  5. Ambrose998800

    Ambrose998800

    Joined:
    Jun 23, 2015
    Posts:
    74
    Wow, thank you! Honestly, I have no idea how to handle Shaders (I 'learned' c# in the last two years by try & error).

    Right now I was messing around with a plane that rises specific vertices to deform it (used that tutorial: https://catlikecoding.com/unity/tutorials/mesh-deformation/)

    Edit: @Flavelius that looks really good. I just can't see what exactly is going on in this script :eek: though it has just three lines ^^' what does the SandUpFrozen Object do?
     
    Last edited: Nov 25, 2018
  6. Ambrose998800

    Ambrose998800

    Joined:
    Jun 23, 2015
    Posts:
    74
    So, to close this thread down - I just picked up this project again, now with some more experience.

    Now it took just a few hours to get more than I wanted:

    I got dynamic 'sandpiles' (displayed by gray orbs) that are created by the windzones wind, that takes direction, speed, obstacles (like pillars) and sand-density in account. The sandpiles are growing by collecting more sand by the sandstorms winds. Their amount is limited for each collecting point (to avoid computing-issues) and will be grinded down again by normal winds.

    All I have to do now is to instantiate a dynamic mesh that envelops all the orbs (like a cloth covering stuff underneath it) and add a sand texture to it...

    SandyWind01.jpg
    [wind with particles to display the streams]

    SandyWind02.jpg
    [sandpiles behind pillars (as obstacles)]