Search Unity

[Release] Water Volume: Advanced Bouyancy

Discussion in 'Assets and Asset Store' started by zibas, Jul 22, 2015.

  1. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Greetings! I've been working hard on making large quantities of objects float naturally and with minimal developer effort. I've just released on the asset store and I'd love to have a conversation here about any problems or how I can better make it fit your needs.



    http://u3d.as/content/popcannibal/advanced-buoyancy

    Efficiently float rigidbodies on animated surfaces. Integrate your gameplay with convenient events and options.

    * Multithreaded
    * Surface area and rotational velocity aware
    * Viscosity occlusion
    * Events for:
    First touch, full exit, center enter, center exit
    * Tracks CPU mesh/skinned mesh deformations.
    * Live swap water meshes for infinite space
    * Very low memory allocations
    * Track special objects' depth without affecting them
    * Sleep objects based on distance from an observer
    * Buoyancy and viscosity affect only underwater portions of objects
    * Directional "flow" force
    * Full source


    See website for the API.
     
    punk likes this.
  2. clinton-reddie

    clinton-reddie

    Joined:
    Mar 20, 2013
    Posts:
    18
    Hello. This looks interesting and potentially useful. My project has been in need of a solution to this problem and maybe this is the answer. Does it work well with any water shader? What happens if a camera is submerged?
     
  3. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Very sorry I missed this post! (I thought I'd get forum notifications. Silly me.)

    Water Volume currently doesn't pay any attention to what shader is on water. It reads the surface boundary from either just a box collider or a box collider and mesh pair. The mesh that defines the surface can be custom animated, skinned or static, but it must not use gpu deforms if Water Volume is going to track the changes.

    Some water effects use GPU deforms others don't.

    Water Volume does not affect the camera. You can easily track any object's distance from the water surface and trigger callbacks when an object enters or exits the water. This lets you know when to turn on and off your own underwater camera effects.

    I would be happy to send you an evaluation copy to see if it meets your needs. Just email support@popcannibal.com.
     
  4. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Does it work on uneven river i.e., water level not fixed?
     
  5. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Yes. Thanks for asking. I made you a quick video demonstrating how it works. Objects will float naturally, but will not "flow" until an explicit flow direction and magnitude is specified.

     
  6. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Thanks for demo and quick response.Its impressive.

    My game is river racing where rivers are in modeler format i.e., multiple planes ,slopes etc has joined to make full river.So will it work in that scenario where different water plane sizes available with object moving at fast speed ?
     
  7. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    It should likely work. I can't make promises without knowing all the specifics of your game, but it doesn't sound that far off from the use case for which I originally developed this asset. You could use multiple Water Volume instances, or dynamically assign whichever meshes are nearest to the player(s) to one master Water Volume instance. You could also use box collider triggers to approximate the water surface.

    Possible stumbling points might be:
    * extreme mesh topography (very uneven vertex distribution)
    * very high poly meshes

    You could use simpler, invisible meshes or box colliders to get around those problems.

    For performance reference, the water surface in the webplayer demo is composed of 4 meshes, each with 128 triangles, and animated using a skinned mesh renderer that transitions between 19 blendshapes.
     
  8. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Heads up: I've submitted an update to the asset store with improved threading for better performance and no thread pool related garbage generation. Also, I've prettied up the documentation. It comes with the asset or you can see it here: http://popcannibal.com/watervolume/
     
  9. labandunga

    labandunga

    Joined:
    Aug 1, 2012
    Posts:
    29
    Can you increase the mass of an object to make it sink?
     
  10. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    580
    Yes I have the same question about sinking. Specifically for a car game.
    Also how it will behave with multiple rigidbody connected by joints?
     
  11. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Yes! Increasing mass will make objects sink. Also, multiple rigidbody's connected by joints will work well. In the demo (http://popcannibal.com/watervolume/) the pontoon shape uses configurable joints to hold the pieces together.
     
  12. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    Looks pretty awesome. A few questions.

    How well would this work with a ship and keel. The keel will be quite heavy to keep the sail boat in the water. If I apply force to torque the sailboat around, will it rotate or will the viscosity keep the sailboat upright?

    I also need high fidelity on a compound object. Probably a lot of joints, maybe 20 Game Objects all being affected while out on the sea. Would this cause a problem? Is there a way to increase the number of times the item is checked for forces so I can have greater accuracy on the floating object?

    Loved the first tutorial by the way, you nailed it.
     
  13. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Thanks! A surface underwater will experience drag when it rotates or translates. So keels and rudders will both work, but can require some massaging of water viscosity, piece mass and piece surface area to get to your liking.

    It will work best at "medium" masses and sizes. Efficiency and accuracy suffers down when you get to individual, bus sized pieces, or weights above a ton but adjusting the "raycast spacing" property can help.


    That should be fine. I made this asset to support my own physics and construction based sailing game based on jointed and gameobjects.(example: https://twitter.com/popcannibal/status/714001325621702656)

    For speed, all objects are treated as rectangular cubes. What will affect buoyancy accuracy most is how you're defining the surface. If you use an animated mesh, more vertices in your mesh will produce greater accuracy (and greater cpu usage).

    Cheers!
     
  14. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    All I can say is, WOW, just wow. This sounds perfect. Thanks for the reply. You are currently at the top of the short list of buoyancy packages. I did the a similar thing with my Building Crafter mod. I needed to create buildings for my game.

    Would it be a good idea to make the hull out of a bunch of cube colliders at angles to simulate the shape of the hull? I only intend to have 1 or 2 ships in a scene at any time and I want the greatest realism possible :).
     
  15. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Thanks for the enthusiasm! I don't want to sell Water Volume short, but being built for speed and quantity over accuracy, means that it will get a great effect for a lot of pieces, but definitely not the "greatest realism possible." I don't know of assets that do this offhand, but there are certainly buoyancy algorithms which do a triangle by triangle breakdown of shapes to achieve greater realism. Here's a nice article about one such algorithm: http://www.gamasutra.com/view/news/237528/Water_interaction_model_for_boats_in_video_games.php
     
  16. DCrosby

    DCrosby

    Joined:
    Jan 13, 2013
    Posts:
    86
    What about Underwater ? I've been looking at a couple of Water Systems, for a Submarine-Like Experience, and what I found is that mimicking dive planes, ballast tanks, and such to level off a sub can be a real headache, especially if it's still looking at the surface, so either it needs to support this, or have some kind of event when I break the surface, and blend on this system, so I can turn off gravity underwater, for that rigid body.
     
  17. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Underwater! DCrosby, an excellent question and a coincidence you should ask. Last week I determined that objects weren't sinking as realistically as I thought they should and think I've fixed it. I've got a yet-to-be-released update with that plus some other improvements (spoiler: lift forces). With the update, if you set the buoyancy value just right, an object with a mass density of 1 unity mass unit will be buoyancy neutral. More will sink, less will float. If you email support@popcannibal.com I can send you an evaluation version so you can see it it meets your needs. I'd love to get feedback on it.
     
  18. julienrobert

    julienrobert

    Joined:
    Sep 15, 2014
    Posts:
    65
    I though the buoyancy is supposed to work with Mesh Collider, but I think it's not working, the objects pass through the water. Am I missing something?
     
    Last edited: Feb 8, 2021
  19. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    I replied via email, but I'll reply here for others who may stumble here: It requires Mesh Colliders to be marked as convex. Apologies for not documenting that.
     
  20. julienrobert

    julienrobert

    Joined:
    Sep 15, 2014
    Posts:
    65
    Thanks for the quick support.
    I have a new question, how is it possible to modify or read the variable flow from another script?
    When I try to do so, I get the error CS0118: 'WaterVolume' is a namespace but is used like a type
    for that kind of code:
    var wv = GameObject.Find("object").GetComponentInChildren(typeof(WaterVolume));

    Is there a confusion because the namespace has the same name as the class?
     
  21. zibas

    zibas

    Joined:
    Sep 15, 2010
    Posts:
    31
    Yeah. All you should need to do is reference it by Namespace.Class. Which in this case is WaterVolume.WaterVolume.

    Here's a working example:
    Code (CSharp):
    1. public class NamespaceReachTest : MonoBehaviour
    2. {
    3.     public WaterVolume.WaterVolume wv;
    4.     void Start()
    5.     {
    6.         wv = GameObject.Find("MyWaterVolumeObject").GetComponentInChildren<WaterVolume.WaterVolume>();
    7.     }
    8. }
    9.  
    Side note: I can generally be reached on the popcannibal discord server (discord.gg/popcannibal) faster than this forum if you have more small questions.