Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Physics Water 2D Tool - GPU based ripple water, realistic buoyancy, water flow & animation

Discussion in 'Tools In Progress' started by Nicrom, Feb 23, 2015.

  1. Stevepunk

    Stevepunk

    Joined:
    Oct 20, 2013
    Posts:
    205
    If this asset can look like this then you have another buyer.
    One question: is it possible to have reflections on the top of the water?
    Screenspace reflections are fine. You can see in the Ori example there are reflections on the top of the water from the background elements. It would be nice to have reflections from objects that intersect the water too..
     
    Zehru likes this.
  2. Zehru

    Zehru

    Joined:
    Jun 19, 2015
    Posts:
    84
    Ask @Nicrom to send you the demo scene of the asset. It's surely the best 2D/2.5D water asset.
     
  3. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Yes. The white line is actually a texture. Although the water shader doesn't look as good as the one found Ori and Rayman games :). I am still working on this tool so I hope to achieve the same quality as in those games someday.
     
    Zehru likes this.
  4. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    At the moment the shader doesn't have reflections, but one of the features that I plan to add in the next update is a new water shader that is similar to the one found in the Ori game. I hope to finish this update in the next 2 months.
     
    overthere, Stevepunk and Zehru like this.
  5. Zehru

    Zehru

    Joined:
    Jun 19, 2015
    Posts:
    84
    Analising your water tool and those pictures that I posted here, I think it's basically the same concept, but they use 2 more things.
    1 - fog inside the water( it can be an animated texture that mimics the fog), been on 2 different z positions: one in the front and one in the middle.
    2 - post processing effects correcting the color and on Ori, there is also a bloom effect.
     
    Nicrom likes this.
  6. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    87
    Hello, I'm new to this stuff...
    Does anyone have a fix for "shooting projectiles" working under water? I want them to be destroyed when they hit the walls, which works when they're not touching water:



    "MissingReferenceException: The object of type 'BoxCollider2D' has been destroyed but you are still trying to access it"

    I tried to use the destroy methods mentioned in earlier posts, but they don't seem to work when you already have an "DestroyMe" script. Anyone has any ideas?

    Thanks in advance,
    Great asset!
    /Peter
     
  7. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi.
    I assume you don't need the projectiles to be affected by the water. In that case you can just exclude them. Give the projectiles a tag, something like "Projectile" than open the Water2D_Simulation script and at the end in the OnTriggerEnter2D() method add the line of code.

    Code (CSharp):
    1. if (other.tag == "Projetile")
    2.     return;
    Place this code at the beginning of the OnTriggerEnter2D() method. This way you don't need the destroy methods mentioned in the earlier posts.
     
  8. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    87
    Works like a charm! Thank you for the quick response
     
    Nicrom likes this.
  9. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Hi,

    Just bought this tool, but I'm having a little problem.

    I don't seem to be able to get it to react to lighting.

    It seems to be 'unlit' all the time, and I'm trying to using it for water in caves etc, which are dark.

    Am I missing some shader that is needed to for lighting?

    Thanks, Rob.
     
  10. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. The shaders that come with the tool do not react to light. If you bought this tool for the shaders and cant use it in your game please sent me the invoice number for this purchase on my email johnq002@gmail.com (the invoice number can be found in the email you received when you bought Water 2D) . I'll ask the Asset Store team to give you a refund.
     
    Last edited: Feb 27, 2017
    Adam-Bailey and Robdon like this.
  11. Robdon

    Robdon

    Joined:
    Jan 10, 2014
    Posts:
    141
    Thanks for the quick reply (and refund offer) Nicrom.

    Its a shame it doesnt work with lighting, as I like the overall water effect you have, but I do need it to be dark in certain places for my game.

    I dont have much experience with shaders, but I'll give it a go and see if I can get some kind of lighting working with it, before I decide to refund.

    Thanks.
     
  12. DCShumway

    DCShumway

    Joined:
    Dec 20, 2016
    Posts:
    6
    Hello!

    I'm currently using your asset for a game development project and I was running into some trouble that I don't know how to fix.

    The game is based around changing states of matter, and we decided to use your asset for the liquid phase. The solid phase is a block (currently the red one) with a BoxCollider2D attached and the gas (the yellow temp) will eventually be a visual effect utilizing particle systems. All three phases of matter are contained under one parent object. Currently, when the blue triangle is in contact with the parent object, the player is able to cycle through the three state objects, deactivating the other two when one is selected.

    However, once you add in a second parent object with three additional state objects, things break. The first parent ends up showing all three of its children at the same time, while the second object fails to show any initial state. And, if you enter the collider of the first object and try to change the state, you end up changing the state of the second object instead. The console also logs the same error almost every frame:


    " NullReferenceException: Object reference not set to an instance of an object
    Water2DTool.Water2D_Simulation.WaterWaves () (at Assets/AssetLibrary/Water2D_Tool/Scripts/Water2D_Simulation.cs:1394)
    Water2DTool.Water2D_Simulation.FixedUpdate () (at Assets/AssetLibrary/Water2D_Tool/Scripts/Water2D_Simulation.cs:791) "

    I've included a video below to demonstrate the problem in action and give you a visual as to what's happening.



    Is there something I need to change in the asset to avoid the multiple water bodies issue? If I can give you any more information to help, please let me know, I'd be happy to provide it.

    Thanks,
    Dylan
     
  13. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. Sorry for the late reply, different time zone.

    From what I can see you are using prefabs to generate water objects. This is something not recommended as it breaks the water. If you want to create a new water object use the Game Objects menu.
     
  14. DCShumway

    DCShumway

    Joined:
    Dec 20, 2016
    Posts:
    6
    Hello! Totally understand the time zone issue, don't worry about it too much.

    I'll try breaking the prefab structures and see if that fixes it, thanks for you assistance!

    Best, Dylan
     
  15. fornetjob

    fornetjob

    Joined:
    Sep 11, 2014
    Posts:
    27
    Can you add layers-exceptions that you do not need distortion?
     

    Attached Files:

  16. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    At the moment you cant do that. I'll add this feature to my to do list.
     
  17. fornetjob

    fornetjob

    Joined:
    Sep 11, 2014
    Posts:
    27
    I want save layer order, but exclude player from destortion, for example
    upload_2017-4-12_15-29-35.png
     
  18. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    To achieve the distortion effect, in the water shader the contents of the screen are saved in a texture and than modified to give the effect of water and distortion. I assume you want the player to look like he is in the water, but is not effected by the distortion effect of the water. So the shader would have to be modified in this case. Regrettably my current level of knowledge in regards to shaders is not at a level where I could implement this feature right now. All I can promise is that I will look into this and try to find a solution in the future.
     
  19. -Orache-

    -Orache-

    Joined:
    Jan 16, 2014
    Posts:
    31
    hi . i used number 1 for sprites pixel per unit . so i had to change water object scale to 50 or 100
    but when other object go into the water suddenly it shot to the top and water has no wave or any changes
    can you help me ?
    (sorry for my english )
     
  20. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. Sorry for the late reply, different time zone.

    The water is not meant to be scaled. Instead of scaling it, click and drag one of the 4 handles to change the size of the water.
     
    -Orache- likes this.
  21. -Orache-

    -Orache-

    Joined:
    Jan 16, 2014
    Posts:
    31
    Oh, I had not seen . thank you ;)
     
    Nicrom likes this.
  22. TheSixthHammer

    TheSixthHammer

    Joined:
    Feb 13, 2017
    Posts:
    6
    Hi, I have a question(possibly bug) - when I have two 2.5D water object with 2.5D clearwater material and I set them on different sorting layer, they both refract the things of the last object sorting layer. I need them each to behave according his own sorting layer. How can I do that?

    P.P. I think they share the same _RefractionTex but I maybe wrong, because I do not know much about shaders :)
     
  23. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. Could you make a screenshot and post it here or send it on my email, so that I could better understand what the problem is. My Email is johnq002@gmail.com
     
  24. DCShumway

    DCShumway

    Joined:
    Dec 20, 2016
    Posts:
    6
    Hello! Another question for you. I currently have a problem regarding the water objects' buoyant force modes. After the companion character game object enters a water object, they cannot fall anywhere below the top of that water object while it is using Physics Based or Linear Buoyant Force modes. Once you switch the force mode to None, the character will fall and hit the ground. A video below demonstrates the issue:



    My current attempted solution has been to try and enable the Physics Based/Linear Buoyant Force Modes only when the companion character is in the water object and have the Buoyant force be set to none at all other times. In order to get access to the Buoyant Force parameter, I declared that I was using Water2DTool before the class and set up a variable to store the parameter as

    Water2D_BuoyantForceMode waterForce;

    Since the script is attached to a parent object that holds the water object, I have to get the Water2D_BuoyantForceMode from the child object, leading me to find the parameter and set the variable with the following code:

    waterForce = this.GetComponentInChildren<Water2D_BuoyantForceMode> ();

    I then attempt to set this variable in both the OnTriggerStay and OnTriggerExit portions of the script so that while the companion character is within the water object and its parent, its BuoyantForceMode is set to Physics Based, and when the companion character leaves the water object and its parent, the BuoyantForceMode is set to None. Currently, the BuoyantForceMode doesn't change at all and playing the scene causes the following error to appear:

    ArgumentException: GetComponent requires that the requested component 'Water2D_BuoyantForceMode' derives from MonoBehaviour or Component or is an interface.
    UnityEngine.Component.GetComponentInChildren (System.Type t, Boolean includeInactive) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/ComponentBindings.gen.cs:58)
    UnityEngine.Component.GetComponentInChildren[Water2D_BuoyantForceMode] (Boolean includeInactive) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/ComponentBindings.gen.cs:75)
    UnityEngine.Component.GetComponentInChildren[Water2D_BuoyantForceMode] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/ComponentBindings.gen.cs:70)
    WaterBodyNoFalls.Start () (at Assets/Scripts/WaterBodyNoFalls.cs:95)

    The line it ties back to is line 95, which is the line where the waterForce declaration is located. Is this an issue I can fix with just revising my script and the BuoyantForceMode will then change? Or is there some other way of addressing the issue beyond just changing the BuoyantForceMode that I could use instead? Thank you so much for your time.
     
  25. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. Most likely the companion object doesn't fall bellow the water because it has a small mass. To make the objects with a small mass sink, just reduce the value of the field Water Density to something like 0.4 or 0.2. When the buoyant force is set to Linear, the field you want to change is called Force Scale.
     
  26. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    87
    I am getting some obsolete warning reports in Unity 5.6. Is this something that affects the water? Is there going to come a 5.6 update for Water 2D? Everything seems to work fine either way. Just curious.

    If you are interested, here is the list:

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(34,27): warning CS0618: `UnityEditor.EditorUtility.SetSelectedWireframeHidden(UnityEngine.Renderer, bool)' is obsolete: `Use EditorUtility.SetSelectedRenderState'

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(114,29): warning CS0618: `UnityEditor.Handles.ArrowCap(int, UnityEngine.Vector3, UnityEngine.Quaternion, float)' is obsolete: `Use ArrowHandleCap instead'

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(277,88): warning CS0618: `UnityEditor.Handles.CubeCap(int, UnityEngine.Vector3, UnityEngine.Quaternion, float)' is obsolete: `Use CubeHandleCap instead'

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(277,38): warning CS0618: `UnityEditor.Handles.Slider(UnityEngine.Vector3, UnityEngine.Vector3, float, UnityEditor.Handles.DrawCapFunction, float)' is obsolete: `DrawCapFunction is obsolete. Use the version with CapFunction instead. Example: Change SphereCap to SphereHandleCap.'

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(281,97): warning CS0618: `UnityEditor.Handles.CubeCap(int, UnityEngine.Vector3, UnityEngine.Quaternion, float)' is obsolete: `Use CubeHandleCap instead'

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(281,42): warning CS0618: `UnityEditor.Handles.Slider(UnityEngine.Vector3, UnityEngine.Vector3, float, UnityEditor.Handles.DrawCapFunction, float)' is obsolete: `DrawCapFunction is obsolete. Use the version with CapFunction instead. Example: Change SphereCap to SphereHandleCap.'

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(283,95): warning CS0618: `UnityEditor.Handles.CubeCap(int, UnityEngine.Vector3, UnityEngine.Quaternion, float)' is obsolete: `Use CubeHandleCap instead'

    Assets/Plugins/Water2D_Tool/Editor/Water2D_ToolEditor.cs(283,42): warning CS0618: `UnityEditor.Handles.Slider(UnityEngine.Vector3, UnityEngine.Vector3, float, UnityEditor.Handles.DrawCapFunction, float)' is obsolete: `DrawCapFunction is obsolete. Use the version with CapFunction instead. Example: Change SphereCap to SphereHandleCap.'
     
  27. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. I am aware of this warning messages. This will be fixed in the next update. Everything should work without problems even with this warning messages.
     
  28. DCShumway

    DCShumway

    Joined:
    Dec 20, 2016
    Posts:
    6
    Thanks for the reply. While changing the Force Scale/Water Density does cause the water spirit to sink, it doesn't address the core issue of the problem, which is that the buoyant force continues to be applied to the object even after it leaves the water object. Even with the Force Scale/Water Density cranked down, the companion character is noticeably affected in its fall outside of the water object. The other problem that arises with changing the force scale/density is that the player can no longer pick up the companion character, as it is too low for the pick-up script to find it.

    Is there some way to ensure that the water object's buoyant force doesn't apply once the companion character has left the object?
     
  29. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Normally if an object leaves the water it should not be affected by it anymore. Is the companion object dynamic, does it have a Rigidbody2D component attached to it? If it has, is the field "Is Kinematic" enabled?
     
  30. DCShumway

    DCShumway

    Joined:
    Dec 20, 2016
    Posts:
    6
    The companion object has a Rigidbody2D attached to it and it is set to dynamic. There is not an "Is Kinematic" field present on said Rigidbody2D, but changing to Kinematic mode just causes it to float in place since the physics forces are disabled.
     
  31. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    It's a little hard to find a solution to this problem without looking at your project. Is it possible for you to create a copy of your project and sent it to me.? You could remove everything that you don't want other people to have, like scripts, sprites and other assets.
     
  32. DCShumway

    DCShumway

    Joined:
    Dec 20, 2016
    Posts:
    6
    Sure thing! I can get that to you hopefully in the next couple hours. Do you have a specific place you want me to send the modified project to?
     
  33. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    OK, than send it to my email johnq002@gmail.com
     
  34. Kidga

    Kidga

    Joined:
    Dec 18, 2015
    Posts:
    6
    Hello, i need to instantiate prefab with water in a runtime, but mesh is missing in prefab and after instance, can u help me to solve this problem?
     
  35. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. Water 2D Tool doesn't work well with prefabs. What I mean is, don't create a prefab from a water object because all of them will end up having the same mesh instance or may not have a mesh at all.
    While Water 2D Tool is not very suited for creating water objects at run time, it's not impossible to create them without using prefabs. Open the script Water2D_Menu and take a look at the method CreateWater2D. The code in this method is responsible for the creation of new water objects.
     
    Last edited: Jun 9, 2017
  36. fabioColombini

    fabioColombini

    Joined:
    Dec 9, 2013
    Posts:
    30
    Hi, I´m thinking to buy it but I would use in mobile app.
    What is the performance in mobile app? Does it work correctly? Is there any recommendation?
     
  37. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. I tested the demo scenes on a Galaxy S4 and got between 50 and 60 FPS. The performance can be improved by reducing the number of triangles the mesh has or by using the Linear Buoyancy (not very realistic, but cheap in terms of performance).
     
  38. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    Hi, playing around with your water2d asset.

    If you don't want a texture and distortion effects from the shader, what would be a good shader to use? Ideally I just want a semitransparent solid colour across the whole thing, no texture or distortions.

    Thanks
     
  39. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. You could use this shader. Do not leave the Texture field empty or you will get errors when you resize the water. The texture will not be visible on the water.

    Code (CSharp):
    1. Shader"Custom/SingleColor" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,0.5)
    4.         _MainTex ("Texture", 2D) = "white" {}
    5.     }
    6.  
    7.     SubShader {
    8.         Tags { "Queue" = "Transparent" }
    9.          
    10.         Pass {
    11.             ZWrite Off
    12.             Blend SrcAlpha
    13.             OneMinusSrcAlpha
    14.  
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.  
    19.             fixed4 _Color;
    20.             float4 vert(float4 vertexPos : POSITION) : SV_POSITION
    21.             {
    22.                 return mul(UNITY_MATRIX_MVP, vertexPos);
    23.             }
    24.             float4 frag(void) : COLOR
    25.             {
    26.                 return _Color;
    27.             }
    28.             ENDCG
    29.         }
    30.     }
    31. }
     
    Last edited: Jun 15, 2017
  40. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    657
    Is there a way to auto-update the width of a Water2D body via code? I'm looking to do the following during Edit mode:

    • Pass Water2D a float, potentially somewhere like OnSceneGUI
    • Have the Water2D body's BoxCollider2D, handles, and texture conform to that width, and have it recenter itself if it needs to
     
  41. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Hi. The Water 2D Tool code is build around the UI handles and Inspector so there are some fields that change only when one of the 2 is used. It may be possible to do what you want if the code is changed a little.

    I'll look trough the code tomorrow and tell you for sure if it can be done. It's pretty late where I live so I won't be able to do it today.
     
    BeeZee likes this.
  42. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    657
    Thanks! I appreciate it. Looking forward to seeing if it can be done.
     
  43. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    Thanks, works like a charm :)
     
  44. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    Could I please add a feature request, it would be great if through script you could make a splash at x position (from an external script), so a bit like RandomWave() but instead you do MakeWave(x) (if x withing bounds, work out index of vertices and make a wave there).

    I'm playing with particles from ParticleSystem triggering through the water, would be nice if they could splash the water.

    On the same theme of external control of Water2D_Simulation, if I want to do that I need to use namespace Water2DTool around my class right? Then I have trouble because my other scripts can't see this class now because they aren't part of the namespace. How do I get around that?

    Thanks
     
  45. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    I am currently working on a major update for the Water 2D Tool. One of the features I want to add in this update is the ability to make splash from an external script.

    In the script that you want to access the Water 2D methods, just add at the top of the script the line of code;
    Code (CSharp):
    1. using Water2DTool;
     
  46. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    Sorry for the late reply, had a busy day.

    Regarding your question about the auto-update of the water width via code. Open the Water2D_Tool script and add this method.
    Code (CSharp):
    1. /// <summary>
    2. /// To be used when wanting to update the water properties externally.
    3. /// </summary>
    4. /// <param name="wWidth">Water width</param>
    5. /// <param name="wHeight">Water height</param>
    6. /// <param name="centerPos">When set to true recenters the pivot point</param>
    7. public void UpdateWaterMesh(float wWidth, float wHeight, bool centerPos)
    8. {
    9.     waterWidth = wWidth;
    10.     waterHeight = wHeight;
    11.  
    12.     float pos = waterHeight / 2f;
    13.     handlesPosition[0] = new Vector2(0, pos);
    14.     handlesPosition[1] = new Vector2(0, -pos);
    15.  
    16.     pos = waterWidth / 2f;
    17.  
    18.     handlesPosition[2] = new Vector2(-pos, 0);
    19.     handlesPosition[3] = new Vector2(pos, 0);
    20.  
    21.     if (cubeWater)
    22.     {
    23.         handlesPosition[4] = new Vector3(0, handlesPosition[0].y, zSize);
    24.     }
    25.  
    26.     if (centerPos)
    27.         ReCenterPivotPoint();
    28. }
    This should make possible to do what you wanted. Let me know if you have any problems.
     
    BeeZee likes this.
  47. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    657
    It works great! Thanks a ton.
     
    Nicrom likes this.
  48. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    Ooh, whats going in the major update?
     
  49. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    421
    This is an update that will be focused on water shaders. I want to make it possible for game developers to use Water 2D Tool in games with different art styles.
    Currently I am trying to implement a water shader that is similar to the water in Ori and the Blind Forest. I also want to make it possible to use water 2D in Pixel Art games, by adding a shader that is made for this type of games.
     
    overthere likes this.
  50. BeeZee

    BeeZee

    Joined:
    Sep 25, 2012
    Posts:
    657
    That sounds awesome. Ori is such a pretty game.