Search Unity

[Released] Dynamic Water Physics - Realistic. Fast. Universal.

Discussion in 'Assets and Asset Store' started by NWHCoding, Jun 1, 2017.

  1. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    DWP is a floating object simulator that uses self-generated simplified mesh to create realistic behavior. Apart from buoyancy, it also simulates dynamic water forces making it suitable for both stationary and moving objects.

    MAIN FEATURES:
    • Fast and easy setup with no tweaking required.
    • Simulate any object shape.
    • Works underwater and in all object positions and rotations.
    • Works with joints and objects constructed out of multiple child objects, e.g. all the demo ships have functional rudders.
    • Water effects are auto-generated using simulation data.
    • Uses dummy mesh simplified by the built-in algorithm meaning high-poly objects do not affect performance.
    • Fast - less than a millisecond for 50 objects in the demo scene on a dual core CPU.
    • Suitable for desktop and mobile.
    • Uses Unity water by default but is compatible with all water systems without waves and those with waves that can provide water height at a requested position, while the effects work only with flat surfaces.
    • Included C# source code, manual and everything seen in the demo.

    Demo video:


    Try it out:
    Windows
    MaxOS
    Linux

    If you find any bugs, have suggestions or need help with the asset fastest way to contact me is through the support email - I usually respond within few hours: http://u3d.as/hjt


    DWP - Unity Asset Store
     
    strich and punk like this.
  2. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    375
    Really nice stuff! I'm loving your physics-based assets mate.

    Is it possible to provide a velocity map that can be queried to apply forces to the objects? IE to move the objects down a flowing river.
     
  3. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    I think I understand what you mean by that - a grid with different force values that are applied to the parts of the boat that are in that grid? If so, that is not possible with the script without some modification. But, let's say that river consists of laminar flow only and that you can provide it's direction to the script as a Vector3, it could be done pretty easily. If you need such modification I can mail you the modified script - it should not take me more than a hour to modify and test it.
     
  4. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    375
    I think I might need something slightly more complex than that - IE at least sampling at the front and back to simulate what might happen if half of the object drifts into a fast current. But I think I could add that on as an independent force on top of this plugin I suppose.
     
  5. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    1,692
    Well that would certainly work.
    As for the sampling biggest problem would not be determining the forces for the current but rather the way the sampling would be done. Say there is a grid populated with values of the current direction in a form of a vector and that the point for which calculation is done is also a vector, finding the closest corresponding point on the grid to the point in question on the boat would be needed every frame and after that interpolating the current values to get the value in that point... this could become very expensive on the CPU very fast. Doing it for 2 or so points on the boat would be a better solution if done right in my opinion.
     
    strich likes this.
  6. DCrosby

    DCrosby

    Joined:
    Jan 13, 2013
    Posts:
    86
    RE-Post from the Beta Forum
    Here is the WaterInterface.cs for UltimateWaterSystem (Which is based on PlayWay, but has a lot of the bugs allready mentioned fixed, and from the results, I see that water height seems to be one of them). :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UltimateWater;
    5.  
    6. /// <summary>
    7. /// Attach this script to your non-flat water system.
    8. /// </summary>
    9. public class WaterInterface : MonoBehaviour {
    10.  
    11.     // Replace "WaterSystem" with your type.
    12.  
    13.     public Water myWaterSystem;
    14.     private WaterSample waterSample;
    15.  
    16.     private Vector3 currentWaterLevel;
    17.     private Vector3 currentWaterForces;
    18.     public float waterHeight;
    19.  
    20.     private void Start()
    21.     {
    22.         // Ultimate Water System
    23.         myWaterSystem = GetComponent<Water>();
    24.         waterSample = new WaterSample(myWaterSystem, WaterSample.DisplacementMode.HeightAndForces, 1.0f);      
    25.         // Hack to let Ultimate Water Wake Up, otherwise it throws an error it can't find water.
    26.         Invoke("StartWaterSampling", 0.5f);      
    27.     }
    28.  
    29.     void StartWaterSampling()
    30.     {
    31.         waterSample.Start(Vector3.zero);
    32.     }
    33.  
    34.     /// <summary>
    35.     /// Return water height y in world coordinates at world point x, z
    36.     /// </summary>
    37.     public float GetWaterHeightAtLocation(float x, float z)
    38.     {
    39.    
    40.         waterSample.GetAndResetFast(x, z, myWaterSystem.Time, ref currentWaterLevel, ref currentWaterForces);
    41.         waterHeight = currentWaterLevel.y;    
    42.  
    43.         // Do not forget to uncheck "Flat Water" under Additional Options of FloatingObject.
    44.        //Debug.Log("Water : " + currentWaterLevel); // Will Slow down performance, to further speed this up make waterHeight Private
    45.         return waterHeight;
    46.     }
    47.  
    48. }
    Might be nice for UnityDynamicWater to support the Water Current Vector Data [currentWaterForces], to push the ship around.
     
    Last edited: Oct 29, 2017
  7. DCrosby

    DCrosby

    Joined:
    Jan 13, 2013
    Posts:
    86
    It for some reason doesn't like water being at any other level then 0, I had my water at 25m (Units) Up and had to move my terrain and everything down (-25m) to compensate. Working on WaterFX Next... I see that the "Particles" aren't really particles, otherwise it would be simple to add foam to water, as UltimateWater has a WaterProjector script, that would take care of any child particle emitters under that transform, and project them onto the water...
     
  8. DCrosby

    DCrosby

    Joined:
    Jan 13, 2013
    Posts:
    86

    So for reference, I'm using a Dual Catamaran, and this water physics package has been the >> ONLY << package that has been able to handle this. I am also getting a strange shadow on the foam, even though I removed it as a shadow receiver, but those are the polish things I'll worry about later.

    On to the point of this post :
    So I was able to add Foam to Deforming Water, but for some reason when the WaterProjector comes along it disables rendering of the water all-together, and the water disappears. What I did here, is duplicate the water particles, assign a shader to it, with the foam material. And then set it up properly, like described in the UltimateWater example, and that works, somehow it has issues with dynamically created geo, which I find odd, since foam is almost always rendered dynamically. I'll send you the modified WaterFX.cs via PM, as I don't want to post any source on here, other than things you have already posted. Maybe it's something you and Ultimate Water can work out. I've gone as far as trying to trace it back to a function "DynamicWater.AddRenderer(this);" and if I disable or remove that it of course doesn't appear.
     
    Last edited: Oct 31, 2017
  9. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    when i install this asset the demo wont run it has error saying that the thrusters are not mapped in the input, when i add a new input and name it Throttle then press the keys nothing happens, same for the bow and other thrusters, the keys work on rudder but not throttle, left throttle or right throttle


    i have removed the sliders and still the keyboard will not control the boats, this asset is not working after loading, it says awsd controls on demo when run but keys are not working
     
    Last edited: May 13, 2018
  10. enlite

    enlite

    Joined:
    Feb 27, 2017
    Posts:
    19
  11. melonhead

    melonhead

    Joined:
    Jun 3, 2014
    Posts:
    630
    How can i get the foam and particles to work with aquas, there is no way of changing the render queue on aquas and the foam shader on dynamic water has no option to change it. have just wasted my money on auas? please help
     
  12. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hi, I just bought DWP and the result is outstanding!
    I just got one question: how do I use floating object script with a gameobject with structures:
    The rigidbody is on top parent of the item and there is no mesh renderer on the same transform of the rigidbody
    There will be multiple mesh renderers under the item's transform, and are buried quite deep:

    Item -- with rigidbody
    holder transform -- with nothing
    function transform -- with my own function scripts
    mesh renderer1 -- only mesh renderer
    mesh renderer2 -- only mesh renderer
    collider1 -- only collider
    collider1 -- only collider

    can this kind of hierarchy work with DWP? How to I set it up?