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.

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. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Could you post the complete error message here.
     
  2. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    62
    I guess it is correct behaviour of your compiler, because it doesn't know what it need to return.
    Just add "return false;" to the end of the code, it should work.
     
    chronowake likes this.
  3. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    62
    Thanks, it's helped.
     
    Nicrom likes this.
  4. chronowake

    chronowake

    Joined:
    Sep 5, 2016
    Posts:
    2
    Excellent! Thank you this worked. Thank you to the original poster as well for the fix. Works great.
     
  5. CainenEX

    CainenEX

    Joined:
    May 27, 2014
    Posts:
    20
    Hi I had some questions about your asset before I would make any purchases. So I was wondering how much impact is has on performance (I'd like to keep things optimized)?
    How does your water fill an irregular area ? I have a cave with objects and tunnels that are filled with water. Do I need to make individual objects?
    Is the water displacement customizable? There are some air pockets that I would not want to be filled with water.
    What happens to the water outside of the "pool" or fill area? i do see it clipping through the wall.
    Does it support non-rectangular shapes?
    If I purchase the asset is any credit towards your required? Are there any legal issues that I should be aware of?

    Thank you for taking the time to read this.
     
    Last edited: Sep 8, 2016
  6. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hello. The performance depends on the platform you are developing for. On a PC there is little performance impact. On a mobile platform there is some performance impact. There are a couple of parameters can be customized to reduce the performance impact.

    At the moment the water shape can be only a rectangle.

    If you mean water displacement feature where the water level rises when an object falls in the water, than you do not have direct control over it. Water 2D Tool comes with the ability to animate the water. You can make the water level rise or go down.

    Giving credit is optional. The Unity Asset Store rules I think are the only things you should be aware of, from what I know.
     
  7. CainenEX

    CainenEX

    Joined:
    May 27, 2014
    Posts:
    20
    Thank you for the response.


    So there is another thing i did want to ask. In my project the character will swim through the water and have to reach air pockets to regain air. Because of this design I would have to layer the water rectangles near or into each other. What doing that with the rectangle cause performance issues or weird physics behaviors?

    Is it possible to not have objects cause water displacement? I would like the water levels to not rise or fall as this would effect my air pocket issue.
     
  8. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Just a small overlapping is not a problem. If you look at the WebGL demo scene "Animation 2" you can see how I separated water rectangles that are close to each other by a small vertical wall. Now if the overlapping is more pronounced you'll have some visual and behavior problems. As you can see from the GIF below the buoyant force is more pronounced for the box in the middle, even though both have the same mass.



    The water displacement by objects is turned off by default. You can turn it on or off in the water object inspector.
     
  9. Stevepunk

    Stevepunk

    Joined:
    Oct 20, 2013
    Posts:
    205
    Is there any option for reflections?
    Or is it compatible with other addons such as SSR?
     
  10. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    The water shader that comes with Water 2D Tool does not have reflections. It should not be a problem to use another shader.
     
  11. AlcyonGames

    AlcyonGames

    Joined:
    Sep 16, 2016
    Posts:
    39
    Hello im not sure if this is the correct place to post it, but i bought the Water2D Tool asset and im trying to use it on my version of Unity 5.3.5f1, but im getting 2 issues by now, one is when i just walk into the water, i know that is because i have an object without rigidbody (i read it on the reviews), but idk where to place the null check code, the other thing is when i shoot something into the water and gets destroyed, i tried the second solution that you put earlier, but the program cant find the "RemoveCollider2DFromList" method, so now im stuck on this.

    Well that's my problem, excuse me if this is not the place to put the question and for my english :3
     
  12. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. Thanks for buying Water 2D Tool. Sorry for the late reply, different time zone.

    On the first issue. Is the object that walks in the water the Player? If so, what character controller are you using, a ray casting based or a physics based character controller (that uses Rigidbody component)?

    On the second issue. Have yo added "using Water2DTool;" in the script from which you call "RemoveCollider2DFromList". Also have you added the "RemoveCollider2DFromList" method in the Water2D_Simulation script. By default this method is not included in the script.
     
  13. AlcyonGames

    AlcyonGames

    Joined:
    Sep 16, 2016
    Posts:
    39
    Thanks for the answer.
    I have a physics based character, the problem is a detection child object that i created, that only has a collider as a trigger and not a rigidbody, but i noticed that the problem comes with every object that doesnt have a rigidbody.

    The second one its ready, i missread the solution, so i thought that the method was included on the script. My fault.
     
  14. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    I think I know what the issue in the case of the first problem. This can be fixed in the OnTriggerEnter2D() method. In the case of the Player check if the the Collider2D that entered the water trigger collider has a Rigidbody2D component attached to it. If it does not have one get the Collider2D of the child or parent that has the Rigidbody2D component. In the case of the non Player objects just skip the objects that do not have a Rigidbody2D component attached to them. Something like this.

    Code (CSharp):
    1. void OnTriggerEnter2D(Collider2D other)
    2. {
    3.     if (!floatingObjects2D.Contains(other) && other.tag != "Ignore")
    4.     {
    5.         // This makes sure only the first collider with the "Player" tag
    6.         // that is detected is added to the floatingObjects list.
    7.         if (other.tag == "Player" && onTriggerPlayerDetected)
    8.             return;
    9.  
    10.         // Add here the code for the player. Get the Collider2D of the object that has a Rigidbody2D.
    11.  
    12.         if (other.GetComponent<Rigidbody2D>() == null)
    13.             return;
    14.  
    15.         floatingObjects2D.Add(other);
    16.         tempObj2D.Add(other);
    17.  
    18.         if (other.tag == "Player" && !onTriggerPlayerDetected)
    19.             onTriggerPlayerDetected = true;
    20.     }
    21. }
     
  15. AlcyonGames

    AlcyonGames

    Joined:
    Sep 16, 2016
    Posts:
    39
    Thanks! that fixed the issue! now the Asset run nicely and smooth :D
    By the way i have a last non error question, is there a way to make a distinction in objects so the water makes ones float up, and some others to sink?
     
  16. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    I'm glad it works :).

    Well since this is a physics based water, the simplest way to do it is to increase the mass of the objects that you want to sink.
     
  17. AlcyonGames

    AlcyonGames

    Joined:
    Sep 16, 2016
    Posts:
    39
    Hahaha so basic and i didnt thought on that, well thanks for your answers, you made a pretty awesome Asset!.
     
    Nicrom likes this.
  18. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    108
    hi! we bought your best Asset very long and very satisfied!

    Now I was faced with an interesting challenge, but not strong in shaders
    Is it possible to modify the shader to create a window effect?

    since the normal MAP is positioned relative to the world, I can`t achieve the desired effect, if you mind, Could you send the right path for the modification of your shader to create a window effect?
     
  19. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. Thanks for buying Water 2D Tool. Sorry for the late reply, different time zone.

    Regrettably my current knowledge level regarding shaders is very small. If you need the reflection effect for the 2.5D (top side of the water) I suggest you to try to use the water shader that comes with unity.
     
  20. Ondatr

    Ondatr

    Joined:
    Oct 29, 2016
    Posts:
    6
    Hi. Thank you for the creation of such useful asset!
    Water 2D Tool worked as described initially and after some tuning it does exactly what I need.

    However, there is one issue I can't currently fix: water sometimes do not generate waves when my player character with multiple 2d colliders falling in it.
    My player has two small circle 2d colliders and one much bigger polygon 2d Collider.
    I assume that water do not react when two identical collider types collide with it simultaneously.
     
  21. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. Thank you for buying Water 2D Tool.

    In the case of the object with the tag "Player" only the first collider that enters the water's BoxCollider2D trigger is saved in an internal list and used to generate waves, the other collider's the player has are ignored.

    You could move up the small circle colliders a little so that the big collider is detected first by the water's BoxCollider2D. If this is not an option open the scrip Water2D_Simulation and in the OnTriggerEnter2D() method (can be found at the end of the script) make sure the collider that is added to the floatingObjects2D and tempObj2D lists is the big collider.
     
  22. Ondatr

    Ondatr

    Joined:
    Oct 29, 2016
    Posts:
    6
    Yes, adding only big collider to the lists solved the issue.
    Thank you for excellent support!
     
    Nicrom likes this.
  23. pokychops

    pokychops

    Joined:
    Nov 7, 2016
    Posts:
    4
    Hi Nicrom. Just bought your tool and looking forward to using it but unfortunately I am new to Unity (not new to coding however). I will take some time for myself to figure out how it works but if you have any pointers how to start out, this is what I'm trying to do: I want to make a 2.5D ocean (has a short fixed z-axis width in addition to endless length (x-axis) and endless depth (y-axis), and the player controls a boat which is a 2d sprite (but has a 3d collision box also with a small fixed z-axis width) and can be steered left and right along the z-axis in addition to going forwards/backwards on the x-axis, which simply moves the sprite closer and farther from the camera within the bounds of the ocean's fixed z-axis width. Also, I want to add many other sprites as collidable objects that also have 3d collision boxes and can collide with the boat if they occupy the same z-axis area. Basically for this part of the game I need a boat can collide with obstacles and has to steer left of right to avoid them. I'm unsure how to star accomplishing this and mixing sprites with the 2.5d ocean. If this simplifies things, I would actually prefer the z-axis movement/positioning to be limited to 3 lanes, and objects can only collide if they occupy the same lane. This could potentially eliminate the need for 3d / z-axis collision detection. Thanks in advance for any advice!
     
  24. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. Thanks for buying Water 2D Tool. Sorry for the late reply, different time zone.

    1. Infinite length water - Having a water mesh that has an endless length (x-axis) is something you don't want to have as it will most likely kill your performance. You can achieve this effect without any performance drop by using the Water 2D Tool animation. You can look at this video to understand how the water animation works in Water 2D Tool.



    Basically what you want to do is have 2 objects that follow the player or the camera on the x axis and animate the water using this 2 objects. This will make the water mesh have a constant size even if you move very far on the x axis.

    You said that you want to have endless depth (y-axis). does that mean that if the player dies he falls endlessly down?

    2. Player movement - Water 2D Tool works with 2D as well as 3D colliders so there should not be problems to achieve what you want. Since you said you want to have the boat collide with other objects in the water I suppose you are using some kind of physics based character controller?
     
  25. pokychops

    pokychops

    Joined:
    Nov 7, 2016
    Posts:
    4
    Thanks for the help, that makes sense! I'll prob have more questions if you don't mind, but just one for now: I noticed all your 2d objects have the Water 2d_sprite script and mesh rendered instead of a sprite renderer. Is this required for 2d objects to interact with the water? I tried using a regular sprite and it didn't seem to interact very well with the water. If this script is indeed required, how do I convert my sprites into Materials to input into the Mesh renderer fields?

    edit: nevermind. I figured out how to make the sprites into materials by looking at your prefab examples, however this only works for single frame static sprites, while my sliced sprite animations cannot be converted into materials or use the animator. How do I get around this?
     
    Last edited: Nov 14, 2016
    Nicrom likes this.
  26. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    34
  27. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. It seams Google has disabled the option to host web pages in Google Drive. I'll have to find another hosting site.

    I think it would be a little hard to achieve this pixel art effect.
     
  28. pokychops

    pokychops

    Joined:
    Nov 7, 2016
    Posts:
    4
    Hi again Nicrom. I am making great progress using your tool. I have almost figured how to do most things, and I have implemented your technique for infinite x-axis water length by using the animator to move left and right walls along with the camera as you said. This works great, however I am using 2.5d water, and while the water does move appropriately in 2d, there is a graphical bug with the 2.5d. As the walls change, the back side of the z-axis of the water flicker between the correct water wave lines and a flat line as if it is constantly trying to update and displaying the default flat waterline first. Is it possible for you to fix this bug on your end? Here is a video I recorded which displays the bug:
     
  29. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. The fix is quite simple. Open the script Water2D_Simulation and go to the method private void RecreateWaterMesh()(can be found at line of code 1297) and replace the the 2 lines of code

    Code (CSharp):
    1. if (water2D.cubeWater)
    2.     vertices[surfaceVertsCount + surfaceVertsCount + i].y = vertices[surfaceVertsCount + i].y;
    with this one

    Code (CSharp):
    1. if (water2D.cubeWater)
    2. {
    3.     for (int j = 1; j <= water2D.zSegments + 1; j++)
    4.         vertices[surfaceVertsCount * j + surfaceVertsCount + i].y = vertices[surfaceVertsCount + i].y;
    5. }
    There are 2 if's so make sure to replace both of them.
     
  30. pokychops

    pokychops

    Joined:
    Nov 7, 2016
    Posts:
    4
    it works! thank you so much! Another quick question: when the walls animate/shift to follow the camera to simulate the endless ocean, I noticed that this creates additional motion in the water and adds new waves which I do not want since there are not actually walls. Is there a way to eliminate the effect of the walls moving on the water motion?
     
  31. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Had a little trouble with this one, but I think I fixed it in the end. I did some changes in a couple of places in the code so I will not post it here since it will result in a very long forum post. So instead could you email me on my email johnq002@gmail.com. I'll send you the 2 scripts that I changed, so you will just have to replace the old ones with the new ones. Also please include your invoice number in the email (the invoice number can be found in the email you received from the Asset Store when you bought Water 2D Tool).
     
  32. antaran

    antaran

    Joined:
    Mar 23, 2016
    Posts:
    6
    WARN about Tag "Player"

    I've been troubled with weird buoyancy. My boat was rotated in Water2D but the boat in the example worked well.

    I made changes on my boat and tested it and finally I got it.

    The problem is THE TAG. When my boat is tagged with "Player" it's intersection polygon is just box.

    <right-bottom boat tagged as "Player">
    screenshot.png

    I find a few options for Player in Miscellanous Section, read some tooltips and understand why it needs.

    However it's so dangerous because tag "Player" - it's so common - acts like magic string and no mention for it in the manual.

    I think this functionality should be changed that user could select which tag is regarded as a player.

    And finally it's great asset! Thanks!
     
  33. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Thanks for pointing this out, I'll add the ability to set which tag should used as "Player" in my next update.
     
  34. Wiremuch

    Wiremuch

    Joined:
    Jan 28, 2015
    Posts:
    104
    Hey this is the water asset we used in our last game- thanks for this! Did notice there was quite a performance impact as it's a mobile game. Did what we could to optimise it but just to double check what parameters do you suggest tweaking?
     
    Nicrom likes this.
  35. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    There are a couple things you can do:
    • Reduce the number of triangles the water mesh has by changing the value of the parameter "Segments To Units".
    • The water shader that comes with the tool is not very optimized for mobiles, so using a more optimized shader could increase the performance.
    • If you do not need realistic water physics, try to set the Buoyant Force parameter to Linear (its not very realistic, but much chipper in terms of performance).
     
  36. Wiremuch

    Wiremuch

    Joined:
    Jan 28, 2015
    Posts:
    104
    Awesome, thanks for the reply! This is more or less pretty much what we did. May tweak the number of triangles some more.
     
  37. McSteed

    McSteed

    Joined:
    Apr 26, 2014
    Posts:
    18
    Great tool.

    I fixed the null reference issue with a simple reference to my Game Manager's bool that already keeps track of the player being destroyed.

    if(GameManager.TheMan.isCrashed)
    floatingObjects2D.Clear();

    I put that in the top of FixedUpdate() in the Water2D_Simulation.cs that way it never calculates the objects destroyed on the previous frame.

    I had to go to the Linear Buoyancy to keep the water from exploding all my motorcycle parts on iPhone. In unity the physical version worked great.

    Is there a water distortion shader that works good for mobile? I miss that effect.
     
  38. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Thanks.

    The current water refraction shader is not very optimized and may not work well on some mobile devices. In the near future I plan to add a refraction shader that is more optimized for mobiles.
     
  39. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    34
    Hey so Im using your plugin for a 2D platformer, and was implementing a "Rising Water" mechanic, which im doing by parenting the water to a pivot gameobject which im scaling in runtime. However when i do this two things change. Both the offset between the visuals and the collider and wave size, how should I go about fixing this?

    Here are some images to explain my issue :)

    http://imgur.com/a/jKhqU

    Thanks! :)
     
  40. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. Scaling the water object is something you do not want to do as it will lead to strange behaviors. Have you tried to use the Water 2D Tool animation for your "Rising Water" mechanic?. Here is a video tutorial on how you can animate a Water 2D object.

     
  41. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    34
    Aha, I see, I'll check that out for sure :)

    Thanks for the prompt response!
     
  42. emongev

    emongev

    Joined:
    Jul 5, 2012
    Posts:
    34
    This worked perfectly since it uses the transform and not any animator information (i am tweening the height by a script). However Im getting a second surface line below, and i have disabled vertical tiling, so its weird to me that its still showing the surface.

    http://imgur.com/LL1h2Jc

    Is there a way to get the surface only on the top without it repeating or stretching? :)
     
  43. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Try to use a texture with a bigger height or decrease the value of the field "Pixels to Units" (this field can be found in the Visual Proprieties group).
     
  44. Zehru

    Zehru

    Joined:
    Jun 19, 2015
    Posts:
    84
    Hi @Nicrom , I want to buy this asset, but first I would like to know/see just 3 things ^^

    1- Can I see a 2.5D build test of this asset?the webgl and webplayer links aren't working.
    2- Can I have objects reacting with the buoyant force and others don't?
    (example: the player doesn't react(as I want him to move omnidirectional while inside the water), but all the stage objects react to it.
    3- Is it possible to do a non rectangular/box water2d object on the scene?
    ( I saw on the video that is possible to not tile the vertical axis, making it possible to do a fade) but still, it would be really nice having some other simple geometric forms ^^

    thank you very much
    cheers
     
  45. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Hi. sorry for the late reply, different time zone.
    1. The WebGL build is hosted on the Google Drive, but because Google removed the option to host web pages on Google Drive it doesn't work now. I'll have to find an alternative web hosting solution.
    2. All the objects that interact with the water are added to a list in the OnTriggerEnter2D() method, so could just set a filter where for example objects with certain tags are not added to this list.
    3. No, the water mesh can be only a rectangle.
     
    Zehru likes this.
  46. Zehru

    Zehru

    Joined:
    Jun 19, 2015
    Posts:
    84
    Okay ^_^ Very good answer. I'm my opinion, your asset looks like the best solution to a 2D/2.5D game with water :)

    I just really would like to see something like a test of the 2.5D features. Maybe a video or a small build with a 2.5D example.
    Can you show us something? ^^
    I hope this can help you sell more of your asset ^_^
     
  47. Zehru

    Zehru

    Joined:
    Jun 19, 2015
    Posts:
    84
    it's okay, you answered quite fast :)
     
  48. Nicrom

    Nicrom

    Joined:
    Nov 17, 2013
    Posts:
    411
    Send me an email on my email address johnq002@gmail.com and i'l send you a small video of the 2.5D demo scene.
     
    Zehru likes this.
  49. morphinegames

    morphinegames

    Joined:
    Mar 13, 2015
    Posts:
    33
    Hey I just wanted to report a bug and the workaround I had to put in place. The scenario is this - I have spikes at the bottom of the water, when the player hits them, he explodes into a bunch of rigidbody2ds. Those interact with the water as expected, but I have a coroutine which despawns them after 2 seconds. This causes an error in the FixedUpdate when it goes to update the waves because those rigidBody2ds are no longer valid.

    I added the following code to the top of fixedupdate

    Code (CSharp):
    1.    void RemoveOldObjects()
    2.         {
    3.             for (var i = floatingObjects2D.Count - 1; i >= 0; i--)
    4.             {
    5.                 if (floatingObjects2D[i] == null)
    6.                 {
    7.                     floatingObjects2D.RemoveAt(i);
    8.                 }
    9.             }
    10.  
    11.             for (var i = floatingObjects3D.Count - 1; i >= 0; i--)
    12.             {
    13.                 if (floatingObjects3D[i] == null)
    14.                 {
    15.                     floatingObjects3D.RemoveAt(i);
    16.                 }
    17.             }
    18.         }
    19.  
    20.         void FixedUpdate()
    21.         {
    22.             RemoveOldObjects();
    And it seems to have fixed the issue for me
     
    Nicrom likes this.
  50. Zehru

    Zehru

    Joined:
    Jun 19, 2015
    Posts:
    84
    Hi!
    After looking at the 2.5D test scene, I'm decided to buy your asset :)
    really amazing!
    Just a small final question: Is it possible to change the color or the alpha of this white line in the border of the water?

    I want to achieve something like this( or better hehehe)

    Ori-and-the-Blind-Forest-Trailer3.jpg rayman_origins-1.jpg
     
    Stevepunk likes this.
unityunity