Search Unity

[RELEASED] Water 2D line

Discussion in 'Assets and Asset Store' started by Eyeofgod, Jun 8, 2013.

  1. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    Water 2D line

    $ScreenShot1.png

    Hi there,

    I have submitted my first package to the Asset Store. It’s a 2d water line simulation. If you don't have any clue of what is this you can check it out here.


    It has been designed for mobile use so the performance is great, 60 Fps on iPad1.

    It comes with a ready to use water prefab perfectly configured, two water shaders (one for PC/Mac standalone and other for mobile), a sample scene and documentation.



    The custom inspector allows you to tweak all the parameters easily (surface color, deep color, mesh subdivisions, surface line color and material, density, size...)


    As a bonus I have included simple buoyancy physics. Note that this is not a package center in buoyancy, so don’t expect lifelike buoyancy ;)


    This is the link to the Asset store: Water 2D line

    Hope you like it!
     
  2. PabloAM

    PabloAM

    Joined:
    Dec 25, 2012
    Posts:
    35
    Nice job!

    The blur effect is compatible with mobile devices??

    Why is needed to upgrade Unity3D to 4.1.3??

    Can water "filled up" when happens a collision ?


    Thanks!!
     
  3. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    Hi PabloAm,

    The blur effect is not compatible with mobile devices (well It works, but destroys performance), and requires unity pro.

    Thats because how the Asset Store works. Because I'am working with 4.1.3 version the Package automatically requires the same version... there is no option to change this. Unity should allow us to manually set the desired version...

    Yes, you can increase the size of the water plane on X,Y on runtime when something enter or exits it. The source code is available so you just have to do whatever you want on the OnTriggerEnter method.

    Thanks for your interest
     
  4. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    It took a while for me to get a decent setting, having a bit more clarification in the documentation on each variable would be nice.

    Would it be possible to add an option to trigger waves/splash on just collision with a CharacterController without use of a rigid body? Can't really make much use of the waves otherwise.

    Edit:

    I've actually run into a pretty big problem! The idle waves simply don't really seem to be working. Even on the included example scene. The surface of the water is flat and super-tense. If I click on the water in the editor, it SEEMS to be doing the proper wave patterns:

    http://i.imgur.com/C30nl0L.jpg

    But when you actually look at how it actually behaves in game or in the editor when it's not selected, the surface curves aren't showing up at all, just a mostly flat surface with an occasional jitter. When rocks are dropped in, there is little to no reaction from the water surface at all.

    http://i.imgur.com/g1izKEr.jpg

    Edit Edit: It seems I've found the problem. It appears that if vsync count is set to 'Don't Sync', the water surface fails to work, for some reason...
     
    Last edited: Jun 20, 2013
  5. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    Mmm... very estrange, isn't it? In which platform is Unity configured? And are you on Mac or PC? I have tested it on Mac, with unity on iOS and on Android without problem. Any more clues will be great
     
  6. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    This is Unity 4.1.5, on a PC with Windows 7. (Just updated to the newest unity yesterday so I could install the asset.)

    I started an entirely new project with just Water 2D to test the Vsync bug, and it still occurs.

    Another really weird clue is that when I tried to create a FRAPS recording of the problem, starting the recording would actually fix the bug. Ending the recording would return the water back to the buggy state. I could literally use the record button as a switch, turning the bug on and off. Unfortunately, it also meant I'm unable to take video of it not working. Could be related to vsync, somehow?
     
  7. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    You were right, it's directly affected by vsync and it behaves different in windows/mac/ios. To solve it you go to the line 367 and change Update() for FixedUpdate() This will solve the issue.
     
  8. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    Thanks, that did the trick!

    Do you have any recommendations on triggering splashes without use of a rigidbody, by chance?

    Edit: Nevermind, we found a workaround!

    Thanks for the great asset.
     
    Last edited: Jun 24, 2013
  9. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126

    Great! I'm here to help :)
     
  10. pixlweaver

    pixlweaver

    Joined:
    Dec 21, 2012
    Posts:
    92
    From the screenshot in the first post, it looks like the water has refraction. However the web build does not. Is there a refraction feature? If so, is there a video or web build that shows it in action?
     
  11. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    I bought your Asset last Week.. and tried a few settings and dummy scenes with it..
    Now i´m a bit helpless.. how can i create a underwater effect (with disortion effect..etc.. like in your screenshot..)?

    I mean..
    I´ve overwater, the water line.. but no underwater (even in your demo, the underwater part is a filled texture, like there´s no transparency in the water)..
     
    Last edited: Aug 9, 2013
  12. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    The water refraction shader doesn't work on the web player. I will check it out again, and see if I can fix it
     
  13. OzDave

    OzDave

    Joined:
    May 19, 2008
    Posts:
    144
    Cheers, I implemented this into my little game.

    $Screen shot 2013-08-23 at 7.44.16 PM.JPG
     
    Sp3ci likes this.
  14. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    I'm still trying to solve the shader for the webplayer...

    OzDave Congratz! IT's really nice
     
  15. PanCrucian

    PanCrucian

    Joined:
    May 2, 2013
    Posts:
    1
    Make offset on the surface of the ship could sail. It is necessary that the ship did not create a splash. I hope I have understood :)
     
  16. vividhelix

    vividhelix

    Joined:
    Mar 20, 2013
    Posts:
    78
    Hi,

    I'm using Water2D with no issues when I drop it into the editor. However, once I make a prefab out of the object containing the water line, when instantiating the prefab I get this problem:

    IndexOutOfRangeException: Array index is out of range.
    Water2D.InitializeWater () (at Assets/Water2D/Code/Water2D.cs:347)
    Water2D.Awake () (at Assets/Water2D/Code/Water2D.cs:202)
    UnityEngine.Object:Instantiate(Object, Vector3, Quaternion)

    It looks like the mesh has no vertices (I debugged it and meshVertices.Length is 0). Am I missing something?
     
  17. vividhelix

    vividhelix

    Joined:
    Mar 20, 2013
    Posts:
    78
    If anyone runs into this, the solution is to remove the mesh filter in the prefab. Alternatively, you can click "Destroy Water" and the apply changes to the prefab.
     
  18. erick_lima

    erick_lima

    Joined:
    Feb 7, 2012
    Posts:
    34
    I made a web player build using Water 2D line and I'm troubling with shader I guess. The water is purple, any ideas?
     
    Sp3ci likes this.
  19. langem

    langem

    Joined:
    Mar 18, 2013
    Posts:
    73
    Hi, I bought this cool asset a while ago. Now that I try to use it with Unity 4.5 it crashes the editor (test scene) when hitting the play button. Any ideas?
     
  20. Eyeofgod

    Eyeofgod

    Joined:
    Jun 25, 2010
    Posts:
    126
    It happens in some hardware + software configurations, normally when using windows 8.1 and an intel integrated card. Try to launch the editor with -force d3d11 or -force OpenGL, and see if it continues happening
     
  21. Deleted User

    Deleted User

    Guest

    Hi

    I am curious, if you wanted water to go flush up against the edge of a platform, how can you stop the first point in the wave going over the top of the platform? Like this:

    https://www.dropbox.com/s/dzcf5pv0k529zpl/wateroveredge.mov?dl=0

    Something a reviewer mentioned, if you don't want waterSplash or afterPeakwaterSplash or splashSounds and you delete them from the inspector panel, it crashes as those objects are missing. Would be good to add a null check (don't use) in your script.

    Also it only works if the gameObject with the rigidbody has a renderer attached. If for example you have a gameObject with no renderer, with a child sprite, then that gameObject won't trigger the water interaction.

    You are using _size in ObjectEnteredWater to effect the number of springs right?

    p.s your link to this forum in your Asset Store description is wrong
    https://www.assetstore.unity3d.com/en/#!/content/9149

    Many thanks!
     
  22. Deleted User

    Deleted User

    Guest

    Here is some code I suggest you add:
    Code (csharp):
    1.  
    2. //FXandsound
    3. if(_emitParticles)
    4.  {
    5. if(instantiatedWaterSplash){
    6. instantiatedWaterSplash.transform.position = myTransform.TransformPoint(meshVertices[selectedVertex]);
    7. instantiatedWaterSplash.Emit(Random.Range(10,20));
    8.  }
    9.  }
    10.  
    11. //Audiosplash
    12. if(splashSounds.Length > 0) audio.PlayOneShot(splashSounds[Random.Range(0, splashSounds.Length)]);
    13.  
    and
    Code (csharp):
    1.  
    2. //Getparticlesready
    3. if (waterSplash) {
    4.   GameObjecttempWaterSplash = Instantiate (waterSplash) asGameObject;
    5.   instantiatedWaterSplash = tempWaterSplash.particleSystem;
    6. }
    7. if (afterPeakwaterSplash) {
    8.   GameObjecttempWaterSplash = Instantiate (afterPeakwaterSplash) asGameObject;
    9.   instantiatedAfterPeakwaterSplash = tempWaterSplash.particleSystem;
    10. }
    11.  
    Code (csharp):
    1.  
    2.    voidSplashParticles(int_column)
    3. {
    4. if(instantiatedAfterPeakwaterSplash) instantiatedAfterPeakwaterSplash.transform.position = myTransform.TransformPoint(meshVertices[_column+firstUpVertex]);
    5. if(instantiatedAfterPeakwaterSplash) instantiatedAfterPeakwaterSplash.Emit(Random.Range(5,9));
    6. }
    7.  
     
  23. Sp3ci

    Sp3ci

    Joined:
    Feb 11, 2013
    Posts:
    6
    I've got the same issue. Do you need Unity Pro for this?

    Edit: Ok changed to the WaterPlane_Mobile and it works now.
     
    Last edited: Nov 27, 2014
  24. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    It crashes on my... why?
     
  25. Xevoius

    Xevoius

    Joined:
    Sep 26, 2012
    Posts:
    25
  26. awejk

    awejk

    Joined:
    Oct 13, 2012
    Posts:
    32
    plugin it's crushed on Unity3d 4.6.1 at the start scene, why?
     
  27. PimajeXenja

    PimajeXenja

    Joined:
    Dec 31, 2014
    Posts:
    10
    Hi, I have recently bought this product, and I have an issue. Everything works fine except for custom objects interacting with the water. They go right through without being affected even though I have attached the floating object script.

    [EDIT] I didn't see the "use 2d physics" checkbox. Cheers!
     
  28. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    So I've used this asset in a project, although the asset isn't supported by the author any more. I've fixed little bugs, 2d buoyancy, custom sound triggering, pinning ends of the water so they are static etc.

    Just tried this on Windows, but it completely crashes in the editor as other people have described above.

    It seems that the mesh generated in the editor when you click create water, isn't liked by windows. In the drawGizmos code, the mesh is returning no vertices (even though you can see some), and when you run the example, when setting up the water script and trying to read the vertices from the mesh its returning 0.

    Here is the code this asset uses to generate the water mesh:

    Code (csharp):
    1.  
    2. //Lets create the mesh
    3.         proceduralMesh = new Mesh();
    4.         proceduralMesh.name = "Water plane";
    5.        
    6.         int hCount2 = widthSegments+1;
    7.        
    8.         int vCount2 = lengthSegments+1;
    9.         int numTriangles = widthSegments * lengthSegments * 6;
    10.         int numVertices = hCount2 * vCount2;
    11.  
    12.         Vector3[] vertices = new Vector3[numVertices];
    13.         Vector2[] uvs = new Vector2[numVertices];
    14.         int[] triangles = new int[numTriangles];
    15.  
    16.         int index = 0;
    17.         float uvFactorX = 1.0f/widthSegments;
    18.         float uvFactorY = 1.0f/lengthSegments;
    19.         float scaleX = width/widthSegments;
    20.         float scaleY = height/lengthSegments;
    21.         for (float y = 0.0f; y < vCount2; y++)
    22.         {
    23.             for (float x = 0.0f; x < hCount2; x++)
    24.             {
    25.                 vertices[index] = new Vector3(x*scaleX - width/2f, y*scaleY - height/2f, 0.0f);
    26.                
    27.                 uvs[index++] = new Vector2(x*uvFactorX, y*uvFactorY);
    28.             }
    29.         }
    30.  
    31.         index = 0;
    32.         for (int y = 0; y < lengthSegments; y++)
    33.         {
    34.             for (int x = 0; x < widthSegments; x++)
    35.             {
    36.                 triangles[index]   = (y     * hCount2) + x;
    37.                 triangles[index+1] = ((y+1) * hCount2) + x;
    38.                 triangles[index+2] = (y     * hCount2) + x + 1;
    39.  
    40.                 triangles[index+3] = ((y+1) * hCount2) + x;
    41.                 triangles[index+4] = ((y+1) * hCount2) + x + 1;
    42.                 triangles[index+5] = (y     * hCount2) + x + 1;
    43.                 index += 6;
    44.             }
    45.         }
    46.  
    47.         //Vertex color:
    48.         Color[] colors = new Color[vertices.Length];
    49.        
    50.        
    51.         for (int i = 0; i <(int)(vertices.Length*0.5f); i++) //Deep vertex
    52.         {
    53.             colors[i] = deepColor;
    54.         }
    55.         for (int i = (int)(vertices.Length*0.5f); i <vertices.Length; i++) //Surface vertex
    56.         {
    57.             colors[i] = surfaceColor;
    58.         }
    59.        
    60.        
    61.         //Asign mesh properties
    62.         proceduralMesh.vertices     = vertices;
    63.         proceduralMesh.triangles     = triangles;
    64.         proceduralMesh.uv             = uvs;
    65.         proceduralMesh.colors        = colors;
    66.        
    67.         MeshFilter myMeshFilter = gameObject.AddComponent<MeshFilter>();
    68.         myMeshFilter.mesh = proceduralMesh;
    69.         gameObject.AddComponent<MeshRenderer>();
    70.  
    Anyone have any ideas as to why this won't work on Windows?