Search Unity

Water Questions

Discussion in 'Editor & General Support' started by nm8shun, Jul 17, 2007.

  1. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Trying to work through water.

    Can I either:
    a) change the shape of the Nighttime Water prefab to something besides the weird oval?
    b) Get it to look like it does in the Prefab on my own geometry? When I place the Nightime Water material on my plane, the water looks thin and stretched - almost like the UV's were projecting the wrong way (although I've checked the UVs and they are correct).

    Thanks.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use the nighttime water material on any object. Is your plane rotated the right way around? The material really only works on horizontal surfaces; try the built-in plane (Gameobject -> create other -> plane) which works fine. The prefab just has the water wave scroll script attached, which is used for an effect on old cards that can't render water properly. So you can add that script to any object too.

    --Eric
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Water uses a couple of scripts and materials to actually work. So the easiest way to change the geometry is dragging the example prefab and changing the Mesh it uses. Full docs are here.
     
  4. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    So, is there anything you can do in indie to make the water plane object undulate behave like water?

    M
     
  5. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    Hmmm... just thinking of somthing very cheap ;)

    Make a lowpoly-copy of the boat, flip it on the horizontal axis, and let the mesh deform a bit back and forth by script... place it under the original boat and make the water slightly transparent... maybe that can fake a little reflection? Also use an animated texture with those typical underwater patterns on the "Mirror-object". Might help to make it more realistic...

    By the way... nice atmosphere in your screenshot! Cant wait to fire some torpedoes there!
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use the mesh scripting interface to do that. There would be some math involved though, but maybe you could get decent results just by applying some sine waves. You could probably even have some interaction with boats on it, but that would start getting a little complicated. Probably best just to fake that part.

    --Eric
     
  7. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    you can access the vertices in the mesh and move them. you'll probably need a pretty dense mesh and some tweaking to get it good. unity can move a fair amount of verts tho. see the procedural example for how to.
     
  8. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    wadamw

    Sorry for hijacking your thread.



    AL. Thanks! E P too...

    -Crumple mesh is very jerky, I like the mirrored boat idea. I've also tried animating it with lots of little bones, but that looks very similar.

    Haven't tried sine curves, that sounds more like it.

    - Excuse my ignorance but what does it mean at the top of a script where it says... the Author is not responsible for any harm or damage? What sort of damage? If I start writing scripts what sort of potential risk am i facing?

    Thanks.

    M
     
  9. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
    didn't see eric posted too. what he said!

    lol... that's just otee releasing scripts with a cya clause. "cover your a**" if it crashes your machine, not my prob!
     
  10. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Aras...thanks much. I swear I had read that same documetation 4 times and for some reason misunderstood that Mesh Filter. Thanks for pointing me at it again. Worked great.
     
  11. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    The sinus curve modifier worked the best... I tried mesh morphing 3 ocean meshes together but couldn't get it to cycle.

    Not as choppy as I would have liked but it's a nice rolling sea. how would I modify the script so there is another curve perpendicular to the existing one?

    Thanks!

    M
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yeah, unfortunately the mesh morpher doesn't really work.

    Well, if you modify the line in the SinusCurveModifier script so that it's

    Code (csharp):
    1. vertex.y += Mathf.Sin(Time.time * speed + baseHeight[i].y + baseHeight[i].z) * scale;
    That gives you a wave only on the Z axis. If you change z to x, then you get a wave only on the X axis. Stands to reason that you can combine the two, and cut the scale in half so it stays consistent:

    Code (csharp):
    1. vertex.y += Mathf.Sin(Time.time * speed + baseHeight[i].y + baseHeight[i].z) * (scale/2)
    2.              + Mathf.Sin(Time.time * speed + baseHeight[i].y + baseHeight[i].x) * (scale/2);
    --Eric
     
  13. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    E

    Good going thanks for that will get onto it and yes, that sounds logical but I am a total newb to scripting.

    M :)
     
  14. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    just wanted to say that's looking pretty good - the waves do alot for the atmosphere ; )
     
  15. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178


    Cool, that worked.
     
  16. heyyeah

    heyyeah

    Joined:
    Aug 9, 2007
    Posts:
    18
    hey all, excellent resources on this page. I also found a couple of interesting things Water Rendering and Simulation and on this opensource opengl project. I'm really interested in the realtime Tessendorf simulation that they discuss and would really like to introduce it into a simple project I'm doing.. I guess I wanted to know from you how much I could get out of Unity in terms of real time simulating a single ocean environment vs. coding in pure opengl which i'm a also a bit familiar with. Any tips appreciated.[/url]

    How did you go with your projects meshpig and wadamw?Cheers
     
  17. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    Still at it... but that's funny because before danger from the deep was ported to mac, you could download the source files which included all the scripts for the water. I mean i have had them for a while. Now you can just downlaod the game and play it incomplete.


    I was just going to post the obvious question, since I think it's in C sharp, how much of that is usable in unity not being familiar at all with coding and on indie until?


    Cheers!

    M
     
  18. rom

    rom

    Joined:
    Jul 2, 2006
    Posts:
    265
    Add this to the end of the SinusCurveModifier to make objects
    float on top of waves

    Code (csharp):
    1. GetComponent(MeshCollider).sharedMesh = mesh;
    Code (csharp):
    1.  
    2. @script AddComponentMenu ("Mesh/Deform/SinusCurveModifier")
    3.  
    4. var scale = 10.0;
    5. var speed = 1.0;
    6. private var baseHeight : Vector3[];
    7.  
    8. function Update () {
    9.     var mesh : Mesh = GetComponent(MeshFilter).mesh;
    10.    
    11.     if (baseHeight == null)
    12.         baseHeight = mesh.vertices;
    13.    
    14.     var vertices = new Vector3[baseHeight.Length];
    15.     for (var i=0;i<vertices.Length;i++)
    16.     {
    17.         var vertex = baseHeight[i];
    18.         vertex.y += Mathf.Sin(Time.time * speed+ baseHeight[i].x + baseHeight[i].y + baseHeight[i].z) * scale;
    19.         vertices[i] = vertex;
    20.     }
    21.     mesh.vertices = vertices;
    22.     mesh.RecalculateNormals();
    23.  
    24. GetComponent(MeshCollider).sharedMesh = mesh;
    25. }
    26.  
    [/code]
     
  19. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    This topic interests me also. How are you making the objects "float"? I added a collider and rigidbody to a sphere, but it doesn't seem to be interacting with the plane surface properly. How should it be working?

    I also thought that the boat's bobbing could be made a bit more realistic looking by using an collider attached to an empty GO, then attach your boat to that with a spring.

    Other ideas?
     
  20. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
  21. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    Targos, glad you changed your avatar image. I thought previously maybe you were being tied up and held to ransom?

    -I haven't opened Unity these past few weeks because just geting right into spline patching. I mean for better boat hulls, but the bike first...

    Just reworking this mess:






    M
     
  22. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
  23. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    An approximate way to model a floating object is to think of it as having a "centre of buoyancy" which generally doesn't coincide with the centre of mass. If you think about a car, the centre of mass is located near the heavy engine - this part of the car would sink first if it were on water. The floating force is applied through the centre of buoyancy. This is quite easy to do using Rigidbody.AddForceAtPosition. The floating force behaves like a compressing spring vertically placed between the centre of buoyancy and the surface of the water. You can probably use little or no damping on the floating "spring" and get a nice bobbing effect for free.

    If the water has waves which are large compared to the size of the boat, then the spring calculation involves detecting where the surface of the water is. If the boat is quite long, then it should pitch with the waves. You could have, say, four buoyancy points in this case, spread out over the length of the boat, each applying a quarter of the total force via its own spring. A wide boat would also need springs across its width, of course.
     
  24. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Lush bike Meshpig.

    Those are scripts Joachim wrote, but the models aren't ideal polycount so the package isnt heavily advertised. Its a fantastic package though, and Im sure Im not alone in my appreciation of this.

    Pete did a bike demo a whileback, and my classmate did a pushbike type bike race last year, Im pretty sure both were based on using raycast colliders...

    Can we see your bike in a "Its parked and Im in first person" scenario? Pls? :D

    AC
     
  25. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    Targos

    Thanks!... sorry for taking up so much space. In it's entirey it comes in at around
    130 000 polys and growing. I ran into all sorts of problems fitting it all together which is why I am rebuilding it now. Will do when I have something.

    Hey, that's the best darn wake, awesome Joachim... How do you mean "not ideal poly count"?

    M
     
  26. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Heya Meshpig,

    The sweet spot for polygon count per individual object == 1500-4000 polies each time. Once yo get above this bottlenecks in performance start to occur. On my beasty g4 I can still get good framerates in moderately sized scenes If I adhere to this, and dont bloat the textures too big, and cut down my use of trilinear filtering. Unity can currently do meshes up to 65000 polygons, but I definately see the perfomance hit here.

    So if your bike was the only thing in a scene at say 60000 polygons, it would probably run ok. But if you used it in a racing game, you'd want to either break it into smaller bits, or cull geometry. Always aim for the sweet spot if you can.
    AC
     
  27. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    Targos

    Cool, thanks for that. The bike grew out of low poly stuff for animation.

    Not intended for games as it is... but yes it has keys in the ignition and dials with moving needles so it will look OK from the rider's perspective. I guess for a game you'd just set up the front end.


    My thrill for the week though is discovering spline patching. I knocked up the rough outline for the bodywork in 3 hours today... it's not great but I can now model it with those views in mind.

    Cheers.


    M
     
  28. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    <offtopic>
    As a die hard motorcyclist I gotta say I'm loving your models there meshpig!
    </offtopic>
     
  29. meshpig

    meshpig

    Joined:
    Aug 17, 2006
    Posts:
    178
    HiggyB

    Thanks dude, I'll get it right eventually.

    Me too, I love 'em... bikes that is.


    M