How to Set Up Dynamic Water Physics and Boat Movement in Unity | Ship Buoyancy Tutorial

Поделиться
HTML-код
  • Опубликовано: 9 ноя 2024

Комментарии • 716

  • @tomweiland
    @tomweiland  4 года назад +92

    Several of you have asked about how I made the ship float in my game, so here's a tutorial!
    Let me know what you think 👇

    • @benedekcsokasi492
      @benedekcsokasi492 4 года назад

      Hello! Great video! Can you /anyone help me? My untiy cube is "delaying", mean Its working weirdly.

    • @Rumplestiltzchen
      @Rumplestiltzchen 3 года назад

      9.5 / 10

    • @Rumplestiltzchen
      @Rumplestiltzchen 3 года назад

      I love how its just above 10 minutes

    • @kokugan
      @kokugan 3 года назад +3

      Hi Tom my Flotter dosn't follow wave movement his y position don't go more then 0.5 and 2.4...., so bettween wave he do levitation otherwise he is submerged like some heightlimiter were set

    • @kokugan
      @kokugan 3 года назад +1

      the probleme was i scaled the plane up.

  • @JamesOfToya
    @JamesOfToya 7 месяцев назад +17

    Love how at the end you're told that's the wrong way to do it and if you want it done right, you're on your own with the link. 10/10 right there.

    • @tomweiland
      @tomweiland  4 месяца назад +6

      It's not the _wrong_ way-it's just a starting point that doesn't scale super well, but the theory behind it works and applies to the shader approach as well 🤷‍♂️

    • @DCRdemonLORD
      @DCRdemonLORD 2 месяца назад

      Well, the main concept in learning game development is to learn it through trial and error so it was indeed a wise choice since we can try and make it even better, thanks for the great tutorial man, @tomweiland

  • @NeatGames
    @NeatGames 4 года назад +70

    I love the way the water moves and looks with the lowpoly look!

  • @Marcos10PT
    @Marcos10PT 4 года назад +10

    If you're finding it hard to understand everything on your first watch through and you're amazed by every commenter seemingly having absorbed the entire thing in one go, do not despair: I have years of experience and still had to do a lot of pausing and rewinding.
    Awesome tutorial by the way! Thank you so much for sharing ☺️

    • @tomweiland
      @tomweiland  4 года назад +1

      Glad you liked it :D

    • @Marcos10PT
      @Marcos10PT 4 года назад +1

      @@tomweiland just for curiosity: have you considered creating the floaters dynamically in the script as points in space instead of manually adding them as gameobjects? Code would be a little more complex but it would be simpler to create new floating objects.
      You could just find the corners of the gameobject programmatically and add 4 floaters to it, or even do it in a fancier way.

  • @toluyole
    @toluyole 3 года назад +47

    This was *AMAZING!* he didn't waste the first 5 minutes with some crazy long intro, and he does the steps quickly while still explaining it pretty well, I mean if your slow to understand stuff I guess this would be pretty complicated and you would've had to watch it in *0.5X* speed, but still this tut was *AMAZING* !!!!! liked and maybe subscribed . . . I'm gonna tell my friends about this

    • @tomweiland
      @tomweiland  3 года назад +1

      Glad you liked it that much :D

  • @tomasbenders922
    @tomasbenders922 4 года назад +66

    Not planning to use this any time soon, but damn that was a good and simple tutorial!

  • @sharkycat1096
    @sharkycat1096 4 года назад +14

    This is a great tutorial! I love how you show which script you are modifying, making it easy to understand and your voice is also easy to understand!

    • @tomweiland
      @tomweiland  4 года назад

      Thanks, I'm glad you liked it :)

  • @SnutiHQ
    @SnutiHQ 4 года назад +13

    Hi Tom! 👋 Thank you so much for making this quality tutorial! 🎉 We took part in the Brackey's game jam 2020.2 and made a sailing game using your physics setup as a basis for our work. Really simple and intuitive setup, which was easy to extend upon. We planned to replace the sine wave function with something more fancy, but it actually turned out so beautiful when we finished our ocean shader and the motion of the boats was nice that we decided to keep it that way. 🌊 (Will be soon posting a devlog referring to your tutorial 💪)

    • @tomweiland
      @tomweiland  4 года назад +1

      This is awesome to hear, I'm glad you found it helpful! Good luck with the voting phase, assuming that hasn't concluded yet :)

  • @mattshu
    @mattshu 2 года назад +2

    I love your style. Easy to comprehend as you code while speaking.

  • @rogeriocruz658
    @rogeriocruz658 4 года назад +4

    What can I say except thanks! I saw some other tutorials online about this and they were all extremely heavy on my CPU. Using some other shaders and the floating points from your tutorial I was able to achieve what I wanted without stressing my CPU. Amazing content

  • @magnusm4
    @magnusm4 3 года назад +1

    3:28 That script would be great as a Scriptable Object for the water. So you'd be able to create multiple instances that each vary without disrupting the original or having to rewrite it either.
    That way you could create many different versions of the water physics.
    The default water physics.
    Denser with more drag on a muddy swamp.
    Or a more sinking ocean of lava with very little waves.
    These short minute tutorials are the perfect format for learning. And you get so much down in so little time and even add small extras like singletons so quickly and clearly which otherwise takes others 30 minutes to confuse you even more somehow. Great work :).

    • @tomweiland
      @tomweiland  3 года назад +1

      Maybe, although you'd need to make sure the floaters know which water instance they're actually floating on.
      Also, I'm glad you like the speed! I myself hate slow tutorials-there's just something extraordinarily excruciating about sitting through any sort of extra fluff when I just want to know what to do next, but skipping ahead is dangerous because you risk missing something :P

  • @editingstuff575
    @editingstuff575 4 года назад +8

    Dude, this is really good and informative. You definitely deserve more

    • @tomweiland
      @tomweiland  4 года назад +1

      Thanks, I really appreciate that!

  • @Spamap
    @Spamap 4 года назад +8

    Finally! A working, easy to understand, and extremely helpful tutorial! Any chance you could do a follow up tutorial on using a shader for the waves, like you use?

    • @tomweiland
      @tomweiland  4 года назад +1

      I'm glad you liked it!
      I don't think I'll cover the shader side of things, mainly because that Catlike Coding article I linked to in the description covers it all. I'd basically just be recreating the article in video form.

    • @Spamap
      @Spamap 4 года назад

      @@tomweiland Ok, that's fine! Would it be hard for me to convert the shaders on catlike coding to shader graph? (As HDRP doesn't support custom shaders other than shadergraph) Sorry - forgot to mention that

    • @tomweiland
      @tomweiland  4 года назад

      That's strange...I haven't used HDRP but in URP you can write custom shaders 🤔
      I believe shader graph has some kind of vertex manipulation node, so it's really just about plugging in the formula you want to use to calculate the height-it shouldn't be too difficult to convert.

    • @Spamap
      @Spamap 4 года назад +1

      @@tomweiland Ok, thanks!

  • @whoshotdk
    @whoshotdk 2 года назад

    You write your function arguments with a preceding underscore. I do that too! First time in *years* that I found someone else who does that hahaha.
    Much respect, thanks for the tutorial!

    • @tomweiland
      @tomweiland  2 года назад

      Not anymore, I got really sick of it 😂

  • @e.d.gproductions7989
    @e.d.gproductions7989 4 года назад +4

    this video was so helpful, I havve not only learned how to make waves but also how to get variables from another script. Thank you so much!! amazing!

    • @tomweiland
      @tomweiland  4 года назад +1

      Glad I could help :)

    • @IWEKNOWI
      @IWEKNOWI 6 месяцев назад

      я тоже хочу, научиться и сделать, что то кроме синусоидальных волн, а именно как в lowpolywater. но не умею, хотелось бы знать как!

  • @WhatShouldIWatch
    @WhatShouldIWatch 4 года назад +13

    If anybody has water with a y position that isn't 0 for whatever reason, and noticed their physics don't line up with their waves, at 4:20 it should be
    float waveHeight = WaveManager.instance.GetWaveHeight(transform.position.x) + WaveManager.instance.transform.position.y;

    • @tomweiland
      @tomweiland  4 года назад +2

      Good point-a few people have run into that issue.

    • @Quinthelas
      @Quinthelas 3 года назад

      Yep this was a problem I ran into just recently as well, my floater was bouncing up and down well below the waves but that fixed it.

    • @victors252
      @victors252 Год назад

      Awesome, ty for this comment so much

    • @ethancotton1549
      @ethancotton1549 Год назад

      im having a problem where at this point when I go to play my cube just falls and I get an error saying "NullReferenceException: Object reference not set to an instance of an object Floater.FixedUpdate () (at Assets/Scripts/Water/Floater.cs:14)" which is on this exact line, I've copied everything correctly as far as I can see so I'm not sure whats wrong with it.
      Any ideas?

    • @endomlic
      @endomlic Год назад

      Double check that the RigidBody is filled in the editor. For some reason the reference removes itself.@@ethancotton1549

  • @Quinthelas
    @Quinthelas 3 года назад

    This has been very useful tutorial in two ways, I have been working on a floating object for a project and I wanted to have it keep moving up and down on the surface and then this tutorial also helped me to figure out how to mimic the movement of the waves in my water without having to try make them real waves.

  • @youneskasdi
    @youneskasdi 3 года назад +1

    Amazing, i will take your lowpoly water over a realistic water simulation any single day.
    not only for performance it honestly looks way better and artistic

    • @tomweiland
      @tomweiland  3 года назад +1

      I love the low poly look as well. Sometimes I feel like I could just gaze at it for hours :P

  • @delcraft7709
    @delcraft7709 2 года назад +1

    One possible improvement is that the actual buoyancy depends on the mass of the object and on the liquid density because the resulting force acting on the object is F_b = (m - rho_liquid * V_displaced)*g. It will add a more realistic immersion of the object depending on its mass and the density of the liquid, w/o adding artificial multipliers. This force is applied only at one point, but its amplitude can be shared between several Floaters to apply a distributed force effect (as if we split the body onto several parts).

    • @tomweiland
      @tomweiland  2 года назад +1

      Right but then you need to set the mass accurately, which then means you have to do a bunch of calculations based on volume, material type, etc. and it just becomes a pain. It's much simpler & more convenient to just have a few multipliers that you can play around with to get something that looks/feels right than something that is completely accurate (which it really never will be because the force would be applied all over the object, not just at one or a few points).

    • @delcraft7709
      @delcraft7709 2 года назад

      Yes, you are probably right, for a casual gameplay not heavily relied on physics this is a simpler solution.

  • @greatbigeyeball
    @greatbigeyeball 10 месяцев назад

    Incredibly good tutorial, I was looking for simple arcade buoyancy and this did the job right away!

    • @tomweiland
      @tomweiland  10 месяцев назад

      Glad you like it!

  • @carny666
    @carny666 4 года назад

    This is the first video of your I have watched and I found it very, very good and I like the pace. I can always pause and rewind. I prefer having to rewind and pause vs. speed the video playback up. Excellent job. I'l; be back.

    • @tomweiland
      @tomweiland  4 года назад

      I'm glad you liked the pace-my first tutorials were definitely much too fast, but just like you, I hate it when a tutorial is really slow and you have to skip ahead :P

  • @xavmanisdabestest
    @xavmanisdabestest 3 года назад +1

    Very nice video my guy I hope one day I become good enough to produce tutorials to help the community like you've done!

    • @tomweiland
      @tomweiland  3 года назад

      Thanks, glad you liked it :D

  • @munyunu
    @munyunu Год назад

    Perfect amount of simplicity and actually great results that make sense.

  • @samueladlard5754
    @samueladlard5754 3 года назад +1

    The water in his game is the most satisfying thing to watch

  • @richardstevenson371
    @richardstevenson371 4 года назад +1

    I wanted to start working on a naval trading/exploration game myself, and this is amazing. : ) Subscribed my friend.

    • @tomweiland
      @tomweiland  4 года назад

      Glad you liked the videos-welcome to the community :)

    • @DunnV89
      @DunnV89 4 года назад

      How this game coming along?? I only ask because it sounds a lot like what I’m trying to create.

  • @greenfigure3941
    @greenfigure3941 4 года назад +111

    epic now i can recreate your game before you release yours

  • @waasar
    @waasar Год назад

    This is a great tutorial for quickly getting into the good stuff. Thanks!

  • @RobLang
    @RobLang 4 года назад

    Superb description. The only feedback is that the contents of your FixedUpdate gets complex fast. I would separate those out into separate methods and the calculations into private get properties, each named something sensible. When you're big hunting 6 months from now, those separations are more powerful than comments and there's no performance drop because the compiler will reduce them.
    Great job, Tom!

    • @tomweiland
      @tomweiland  4 года назад +2

      Thank you :)
      Thinking about it now, you're probably right. I could have definitely pulled out the drag and buoyancy forces into separate methods-it just didn't feel super complex as I was writing it (especially since it's less than 10 lines).
      "Big hunting" ?

    • @RobLang
      @RobLang 4 года назад

      @@tomweiland lol bug hunting. I love phone swipe keyboards!

    • @tomweiland
      @tomweiland  4 года назад +1

      Ah, that makes a lot more sense!

    • @RobLang
      @RobLang 4 года назад

      @@tomweiland I find that using the right words really helps in comprehension! Didn't bother teaching me THAT in school!

  • @plokkum
    @plokkum 3 года назад +2

    When applying the buoyancy force, subtract its own velocity at that specific point. Should probably help with the bounciness you’re experiencing. The same goes for the torque.

    • @tomweiland
      @tomweiland  3 года назад

      Have you tested this? I'll give it a shot, although that doesn't seem right since buoyancy is an acceleration isn't it? Also do you mean to subtract the specific floater's velocity or just he ship's?

    • @plokkum
      @plokkum 3 года назад

      @@tomweiland I mean subtract the rigidbody’s velocity at the floater’s position. I haven’t tested it in a buoyancy setup. But your rigidbody already has a velocity, since you’re adding one on top of that to reach your desired position, your ship will overshoot it resulting in a bouncing effect. If not, sorry for wasting your time. Would love to hear the result though. I’m not near a computer so I can’t test it right now.

    • @tomweiland
      @tomweiland  3 года назад +1

      I'll give it a shot, although on a theoretical level I'm not convinced :P

  • @farhanhakim2189
    @farhanhakim2189 3 года назад

    Honestly, i love this channel
    Why?
    1. You are my hope after Brackeys gone
    2. You also gave us many tutorials, because showing your game only is very boring, and its like arrogant (CMIIW, maybe my English is wrong)
    3. You gave us tutorials, and you also use it to your game, which is great
    4. I love your C# networking series (maybe if you can, please continue the series 😀)

  • @onelonewolf2944
    @onelonewolf2944 4 года назад +1

    Thank you for this utterly amazing tutorial. I learned what I wanted and you presented the information in a clear and concise format. Defenitely going to implement this floating into my game.

  • @trolleycartwheel9409
    @trolleycartwheel9409 Год назад

    Thank you for this, I was also looking for tutorias like this for quite a while.

  • @benjamenkuhman6808
    @benjamenkuhman6808 Год назад +1

    I know this is old but this may help some who experienced some stuttering the same way I did. Both times that AddForceAtPosition is called, multiply gravity by Time.fixedDeltaTime as well. Seemed to smooth things out nicely.

    • @tomweiland
      @tomweiland  Год назад

      🤔

    • @monfort537
      @monfort537 Год назад

      Yep helped me as well. In the video, the water drag is multiplied with fixedDelta time but not the gravity calculations

  • @Hazzel31337
    @Hazzel31337 Год назад

    awsome thank you, quick, packed with information, easy to understand and follow

  • @fabianvelander
    @fabianvelander 4 года назад +1

    this is a great tutorial, I wil probably look back at this video everytime I make a game with water in it.

    • @tomweiland
      @tomweiland  4 года назад

      Thanks, I'm glad you like it :)

    • @dart3dstore46
      @dart3dstore46 4 года назад

      Tom Weiland good video man

  • @amongthecouch23
    @amongthecouch23 Год назад +1

    this would've helped me more if I wasn't making water while having multiple heights of objects and terrain i did something similar with movement and ended up having to redo the entire thing a few days ago because it worked if the character wasn't moving up if it was flat terrain this would work way better thought i would mention it for people looking to do something with different heights of terrain and or water.

    • @tomweiland
      @tomweiland  Год назад +1

      Are you talking about water at different heights in the world, like rivers and lakes? If so, you're right that (as is in this tutorial) this solution only works with water that's at the same height.
      If that's not what you meant, then perhaps using some punctuation would help clarify what you're trying to say 😅

  • @K-Anator
    @K-Anator 3 года назад

    This might just be exactly what I'm looking for. I've been messing around with the idea of a game based on hovering vehicles. I've used a modified buoyancy script I found on the Unity forums in the past, and replaced "ocean height" with a downward raycast, and did some messing around to have it "float" a certain amount above whatever the cast hits. But, that script is a tad more feature rich, and involves doing a bunch of stuff I don't understand with voxels and cutting up the mesh, and it was probably more resource intensive than what I need.
    With something like this, I should be able to quickly whip up a vehicle that hovers using the actual positions of the thrusters (or whatever I end up making the vehicles hovering method, hoverpads?), without having to expend a bunch of resources voxelizing crap.
    Looks like I know what I'm doing this evening. Thank you!

    • @tomweiland
      @tomweiland  3 года назад +1

      That's an interesting application for this kind of setup-I guess you'd probably raycast downwards at each floater instead of sampling a wave equation, and then apply an upwards force based on how far away the ground is 🤔

    • @K-Anator
      @K-Anator 3 года назад

      @@tomweiland Exactly ;)

    • @K-Anator
      @K-Anator 3 года назад

      @@tomweiland So, I've been messing around with things, if you'd like to see what I came up with, check it out: ruclips.net/video/aUgbtHNIo1k/видео.html
      It needs a lot of work on my end, but your snippet here was essential in getting things going.
      I moved away from having 4 separate empties with a "hover" script, and instead moved all the logic to the parent, using a foreach on an array of "hover point" empties. I'd like to expand on this later by having the "thruster" destructible, and when destroyed fire off an event, which will then update the list of hover points.
      Anyway, the prototyping has been fun so far, you've definitely helped spark a new fire under my ass to work on gamedev stuff, and I think I'm gonna have a lot of fun with this.

  • @deathcoredude6565
    @deathcoredude6565 3 года назад

    don't understand most of it so far but this is phenomenal to me, awesome job! :D

  • @lordpickle6442
    @lordpickle6442 3 года назад

    Great tutorial. Sure, The World Wide Web Is Great, But You, You Make Me Salivate.

    • @tomweiland
      @tomweiland  3 года назад

      I don't know what to do with this information 😳

  • @gloriousptr
    @gloriousptr 4 года назад +1

    Your channel is treasure! Really good tutorials, keep it up!

  • @RazixStyle
    @RazixStyle 4 года назад +1

    Great video Tom! Cant wait for the next one

  • @keventy6114
    @keventy6114 4 года назад +1

    This is awesome. Could probably link this up to some type of stormy sea/weather system

    • @tomweiland
      @tomweiland  4 года назад +2

      For sure! I'll be doing that at some point in my own project.

  • @foreignwarren7361
    @foreignwarren7361 3 года назад

    Flippin awesome Tom, keep them coming please!!!

    • @tomweiland
      @tomweiland  3 года назад

      Glad you liked it :D

    • @foreignwarren7361
      @foreignwarren7361 3 года назад

      @@tomweiland the floater script is working on my cube bit not my model ship with a rigid body any ideas

  • @RugbugRedfern
    @RugbugRedfern 4 года назад +3

    Ooh, a new series!

    • @tomweiland
      @tomweiland  4 года назад +3

      Probably not :P
      There's not _too_ much more I can cover here that isn't already explained in that article I linked in the description. If there was a _huge_ amount of demand, then maybe, but making tutorials isn't exactly the most exciting work...

    • @bustosmusic
      @bustosmusic 4 года назад

      @@tomweiland I vote for yes, also you have a new suscriber as this is the thing I was literally looking for

    • @tomweiland
      @tomweiland  4 года назад

      @@bustosmusic thanks for subscribing, I'm glad I could help :)
      I'm assuming you're voting "yes" for turning this into a series, right? What else would you want to see covered (not making any promises, just not really sure what else would need to be explained)?

  • @digital_gaming8568
    @digital_gaming8568 3 года назад +1

    This is an amazing tutorial i learned exactly what i needed

  • @eddu369
    @eddu369 4 года назад

    dude, youre an absolute legend. looking forward to seeing your progress with this game:D ty

    • @tomweiland
      @tomweiland  4 года назад

      Thank you :P

    • @eddu369
      @eddu369 4 года назад

      @@tomweiland hey man, i know youve got a lot going on. but if you can, could you explain how you adjust the wave manager formula to match whats in the shader? ive tried picking apart the shaders equation and reassembling it in normal script but the variables just dont work.

  • @decidev
    @decidev 3 года назад +1

    Damn bro you thought of everything! Super helpful for my project! Thanks!

  • @BlackMandragore
    @BlackMandragore 4 года назад +2

    Very nice video. Thank you.
    I have a question though : why do you introduce the displacementAmount ? What is the purpose of it ?
    And by extension, why using displacementMultiplier in drag / angular drag formulas, instead of using the displacement factor, which is not multiplied (that is Mathf.Clamp01(-transform.position.y / depthBeforeSubmerged ), which always stand between 0 and 1).
    The displacementAmount seems to be like a constant introduced to give a better result/dynamic rather than being physically related to something. Am I wrong ?

    • @tomweiland
      @tomweiland  4 года назад +1

      The displacementAmount is meant to approximate the total amount of water displaced if the object is entirely submerged. We use the displacementMultiplier because the object isn't always entirely submerged.
      For the drag, you can use the displacement "factor" instead if you like. Honestly this is just an example of how you _could_ mimic buoyancy, so if you think something else might work better, just try it out.

  • @brandon-leecoskey5942
    @brandon-leecoskey5942 4 года назад

    This is awesome, and your game looks really good! It would be really cool to see a tutorial on how you might get your wave manager to produce the same movement as vertex displacement created in shader graph.

    • @tomweiland
      @tomweiland  4 года назад +1

      Thank you!
      To get the wave manager to produce accurate movement for your shader, you just need to make sure that both the wave manager and the shader are using the same formula and offset to calculate the waves :)

    • @brandon-leecoskey5942
      @brandon-leecoskey5942 4 года назад

      @@tomweiland haha yeah that's the tricky part, because shader graph is a visual thing it's hard to work out exactly which combination of nodes and in which order will produce the same movement algorithm.
      But I'll keep at it, this tutorial has definitely taken me one step further towards achieving it. Thanks again!

    • @tomweiland
      @tomweiland  4 года назад +3

      @@brandon-leecoskey5942 ah right, I always forget people use shader graph-I still write all my shaders with code :P

  • @ajaykumar-qw3qr
    @ajaykumar-qw3qr 4 года назад

    Awesome Tutorial. I will try it Now.
    Thank you .

  • @renatusdev
    @renatusdev 4 года назад +1

    Tom The Man! Thank you bro, using this immediately rn. You got a sub!

    • @tomweiland
      @tomweiland  4 года назад +1

      Glad you liked it, and welcome to the community :)

  • @Zarksch
    @Zarksch Год назад +1

    hey this is a really amazing tutorial but I wish you went more in depth on how to use it together with a shader. I followed the tutorial you linked but cant seem to find a way to properly adjust the physics to that

    • @tomweiland
      @tomweiland  Год назад +2

      You just have to recalculate the buoyancy the same way the mesh is deformed. This video has a good explanation of how to do it (ignore the GPU readback stuff, what's important is that sampling the wave equation multiple times and adjusting the sample point on each iteration gets you a pretty accurate result): ruclips.net/video/kGEqaX4Y4bQ/видео.html

    • @Zarksch
      @Zarksch Год назад +1

      @@tomweiland Thank you for that very quick and great answer even thpugh this is an older video !:))

  • @Joewa_
    @Joewa_ 3 года назад +1

    I had a question about implementing the water on a large scale using the GPU. Following the link to the tutorial by Catlike Coding, I am able to run the wave as a shader but obviously this leaves out the method of implementing buoyancy/swimming physics. My question is whether you are running the surrounding water "chunks" on the GPU and the swimming physics on the CPU for the players immediate environment (ie. only simulating the physics for a few chunks the player is near but running identical waves on the GPU farther away) or am I missing something? Awesome video

    • @tomweiland
      @tomweiland  3 года назад

      I only simulate the physics for the exact point that I need it. You can use the same formula (or an approximation if you're using Gerstner waves) on the CPU to get the height of the water at any give point, regardless of whether you actually have a water plane there or not.

    • @Joewa_
      @Joewa_ 2 года назад

      @@tomweiland Thanks for the reply! I feel I've been able to get things working well with your advice, but I had another question regarding how you organize large areas of water and coordinate the waves across planes? I am completely lost on how to approach this

  • @Inspiration-Motivation0
    @Inspiration-Motivation0 29 дней назад

    Hey Tom, great tutorial. I implemented the GPU rendering from the tutorial you linked and I managed to get a plane with any number of vertices I want. But, no matter what I do, the water looks... bland? I guess what I'm saying is I can't see the differences between the individual triangles and they all seem to blend together even with a super low vertices count. I understand this might be a trade secret, any way you could give me a hint ? ;)
    Really appreciate the tutorial, this was exactly what I was looking for and you've earned a subscriber.

  • @frankzander5946
    @frankzander5946 3 года назад

    absolutely awsome :-) just what the doctor prescribed! Many thx!

  • @camy_dev
    @camy_dev 3 года назад

    The fact that you were able to teach this idea in 10 min is impressive this is a really awesome tool. Just one question I noticed the offset float keeps increasing obviously. could there be any downside to this if the float reaches its max. I was thinking you could set it to 0 after its greater than a certain number or reverse the offset to decrease instead of increase idk thanks.

    • @tomweiland
      @tomweiland  3 года назад

      Most formulas you might use to generate waves will repeat at some point (an untransformed sine wave has a period of 2π, which is how often it repeats), so you could use some math to figure out the period of your wave equation and reset the offset every time you reach that value. That should result in a seamless transition (assuming you do the math right 😆).

    • @camy_dev
      @camy_dev 3 года назад

      @@tomweiland yea noticed that too lol to be smooth it has to reset at the right time thanks for the response. very cool system

  • @SteveTheExploiter
    @SteveTheExploiter 4 года назад +1

    Thank you! This was VERY informative!

  • @Wisse37
    @Wisse37 4 года назад +1

    Great video! one question: how did you rewrite the formula from the shader to the WaveManager?

    • @tomweiland
      @tomweiland  4 года назад +1

      I'm assuming you're using the Gerstner waves in the shader? In that case the closest you can get to a mathematical formula is an approximation-it won't be exact but I can send you the code on Discord if you like.

    • @Wisse37
      @Wisse37 4 года назад

      @@tomweiland Thanks for the reply, i am in your discord and found other people asking, so i managed to get the formula.

  • @Yoctopory
    @Yoctopory 3 года назад

    Thank you so much!! This is an amazing tutorial!!

    • @tomweiland
      @tomweiland  3 года назад

      I'm glad you liked it :D

    • @Yoctopory
      @Yoctopory 3 года назад

      @@tomweiland Best part of it is that I can load heavy cargo as rigidbodies onto the ship and the ship sinks into the water and tilts according to the weight. Looks really cool :)

  • @rafante2
    @rafante2 2 года назад

    I've became a huge fan of yours. Please don't stop. I'm using your RiptidingNetwork and it is surprisingly great for me. I've found an article teaching how to implement player prediction, server reconciliation, interpolation and lag compensation using a framework that looks a lot like your RiptideNetworking it's name is Darkrift I guess. So I think with DOTS (ECS) and multiple server containers handling different contexts of the game using Redis to synchronize data between containers and orchestrating them with kubernetes I can implement a viable mmo rts / rpg. With the adittion of solidity I can implement nft and real money on the game. What do you think?

    • @tomweiland
      @tomweiland  2 года назад +1

      I'll be honest, I haven't really dealt with the devops stuff (containers, kubernetes, etc.) so far, so my knowledge in that area is pretty surface level, but what you said sounds okay as far as I can tell 😅

    • @rafante2
      @rafante2 2 года назад

      @@tomweiland Nice! I've been trying to implement CI/CD with github Actions using game.ci workflows, but they don't yet support server build just the client. They have a container image with unity that I can use to build the server and upload to my digital ocean droplet, but it's a 9Gb sized image and there's no chance I have to pull it on every commit. I'm trying to find whether is there a chance to cache it for the subsequent commits. I sincerely appretiate the work you've been done so far. Please don't stop posting contents. I loved your implementation of buyoancy. I was trying to do that for a long time and now I think I'll be able to. Thank you so much!

  • @pixelpeelygaming
    @pixelpeelygaming 3 года назад

    Thanks so much! This helped me a ton!
    I have my own waves, but since I am not experienced when it comes to performance, I don't know how to turn my script into a shader so it runs on the GPU instead of CPU.
    Maybe you could make your own video about it? You do a really good job at explaining things, and you helped me a ton with networking!

    • @tomweiland
      @tomweiland  3 года назад +2

      Did you read the article that I linked to in the description? It goes through the process of creating waves in a shader step by step.
      At the moment I have no plans to make a tutorial on that, but I'm glad you liked the networking videos :)

  • @maxtoka5867
    @maxtoka5867 10 месяцев назад

    Finally helpful guide.

    • @tomweiland
      @tomweiland  10 месяцев назад

      Glad it was helpful :)

  • @uvz5875
    @uvz5875 3 года назад

    Great Tutorial. Altho for my low skill some stuff is hard. Wish you could show us how you work with the shader for performance or guide a little more on how a GPU shader will require a formula change?

    • @tomweiland
      @tomweiland  3 года назад

      Just because you simulate the waves in a shader instead of on the CPU doesn't mean you need to change the formula, but there are much better formulas to generate waves than using a Sine function (look into Gerstner waves). I just happened to mention the two at the same time, but you can do one without the other.

    • @uvz5875
      @uvz5875 3 года назад

      @@tomweiland Ty for replying. Gonna Try your tutorial with GPU shader from the asset store. No nothing about shaders and wave formulas:( . Hope it works. Even if it isnt 100% accurate. Need just the feel.

  • @richardstevenson371
    @richardstevenson371 4 года назад +1

    Tom, a couple of questions:
    1. I'm still relatively new to writing shaders. I've followed the CatLikeCoding tutorial (and threw them a donation, wow, what a great tutorial), but I'm curious how you got the lighting to emphasize each tri, for that nice low-poly look. My shader looks really smooth and doesn't have the same charm.
    2. Like the shader, I have set up my WaveHeight function to just use a time figure so I don't have to update the offset each frame. I'm using Time.timeSinceLastLoad to try to sync them, but I'm not sure I've gotten it right. I'm curious what technique you use to sync the shader and the function.

    • @tomweiland
      @tomweiland  4 года назад

      1. The low poly look is achieved by having the entire surface of each triangle use the same normal. If a triangle shares vertices with neighbouring triangles, the normals of those vertices will be an average of all the surrounding face normals (I hope that makes sense). My low poly shader is sort of my "secret sauce", but I'll point you in the right direction-in order to have a universal face normal, each of the triangle's vertices need to have the same normal value, and what's most commonly done is to simply split vertices, meaning each triangle has its own unique set of vertices (since you can only have one normal per vertex).
      Alternatively, you can ignore the normals stored in the mesh data and recalculate them in a shader. This can be done using geometry shaders (which allow you to perform calculations on a per-triangle basis rather than per-vertex/per-pixel), or you can use the screen space derivatives in the pixel/fragment shader function. Over the course of several months, I probably read every article/question/forum post out there relating to low poly rendering trying to figure this out :P
      2. I set the offset for both the WaveHeight method and the shader manually.

    • @richardstevenson371
      @richardstevenson371 4 года назад

      ​@@tomweiland I managed to hack something together with a flat-cell shader I found by incorporating the vertex displacements... Much studying to be done on my part to understand it beyond that, though.
      I'll try not to make something too similar and step on your creative toes!

    • @tomweiland
      @tomweiland  4 года назад

      @@richardstevenson371 that sounds like an approach that I'm not sure I've heard of. If you don't mind sharing I'd love to know how it works-maybe we can talk on Discord?

    • @richardstevenson371
      @richardstevenson371 4 года назад

      @@tomweiland Whoops! I wouldn't mind, but I can't really offer any expertise myself. I simply implemented the wave functions into a shader I found online:
      hextantstudios.com/unity-flat-low-poly-shader/

  • @sleepykittyMMD
    @sleepykittyMMD 11 месяцев назад

    dang thats awesome. granted i'm still too new to know how you managed to do any of that. but hopefully one day all of this will make more sense😅

  • @thepotatopeel6478
    @thepotatopeel6478 3 года назад +2

    hey, great video, but i have a problem,
    if I have already made some waves by modifying the position of the vertices with shader graph, how can I match the buoyancy of my cube with the position of the shader vertices? Thanks for your time and good luck with your game :)

    • @tomweiland
      @tomweiland  3 года назад +1

      You just need to make sure that you're using the same formula and offset in the shader as you are in the height calculation method and it'll give you the same value.

  • @minininja2615
    @minininja2615 4 года назад

    Great tutorial, I'm new to this and am wondering how you'd go about implementing multiple Sin waves, any help is appreciated.

    • @tomweiland
      @tomweiland  4 года назад

      Simply call the Sin function multiple times, each time adding the returned value to the height variable.

    • @zach2879
      @zach2879 4 года назад +5

      @@tomweiland if i use a shader for the waves, how would I get the vertices heights?

  • @FERRRU
    @FERRRU 3 года назад

    thankyou tom weliand

  • @ahmada1629
    @ahmada1629 4 года назад +2

    Concerning doing waves in a shader, how do you get the height of the waves? I also reckon the WaveManager script is no longer needed if you use a shader? Thank you for this tutorial!

    • @tomweiland
      @tomweiland  4 года назад +1

      You get the height of the waves from the WaveManager script (meaning it _is_ still needed) regardless of whether or not you manipulate the mesh in a shader or on the CPU. You just need to make sure that the shader uses the same formula as the WaveManager script.

    • @richardstevenson371
      @richardstevenson371 4 года назад

      This gets pretty tricky with a bunch of stacked Gerstner waves. Still debugging : )

    • @tomweiland
      @tomweiland  4 года назад

      @@richardstevenson371 if you make a method that returns the height for a single Gerstner wave, then all you have to do is call it multiple times and sum the results.

    • @liamperkins398
      @liamperkins398 3 года назад

      @@tomweiland I've been trying this but the results arn't what I'm expecting. Does something need to change with the offset or speed variable from the more basic waves?

  • @asafbenjaminov2635
    @asafbenjaminov2635 2 года назад

    Hey, great video!
    Where did you place the floaters on the ship? im getting some weird movement when the waves get bigger or at the beggining of the simulation

    • @tomweiland
      @tomweiland  2 года назад

      Just evenly spaced around the hull. How many you use depends on how big the boat is. How are you scaling up the waves? If you're changing the actual scale of the water plane's transform, that's probably why you're getting weird behavior because doing so doesn't change the scaling of the waves that are used in the physics calculation.

    • @asafbenjaminov2635
      @asafbenjaminov2635 2 года назад

      @@tomweiland no im changing it in the actual wave height parameter and not scale.
      I get the weird bounces at the beginning and then the ships float nice.

  • @ivanakarain12345
    @ivanakarain12345 Год назад

    amazing tutorial! But i have a question - how can i use it with gerstner waves? (i did everything by catlike codings tutorial)

    • @tomweiland
      @tomweiland  Год назад

      You just calculate the height on the CPU (aka via C#) using the same formula.

  • @ThePoinball
    @ThePoinball 4 года назад +2

    Awesome ! thanks for this good knowlege !

    • @tomweiland
      @tomweiland  4 года назад +1

      Thanks, I'm glad you've found it useful :)

  • @Hero.S
    @Hero.S Год назад

    I love your water dude it is so cool

  • @tomharris4622
    @tomharris4622 4 года назад

    Great video Tom, is it possible to put objects, like the player character on the boat without messing with the physics?

    • @tomweiland
      @tomweiland  4 года назад

      Yes, that's possible, and I do that in my own game too. If your player is weighing the boat down too much, try increasing its mass a bunch.

    • @tomharris4622
      @tomharris4622 4 года назад

      @@tomweiland mass was the main issue, increasing that a large amount solved my issue. Thanks

  • @monoculosofficial9934
    @monoculosofficial9934 Год назад

    Awesome tutorial! I've been working on shader programming recently and am making an ocean shader at the moment. I'm wondering how you get your vertex data back out of the shader and into a C# script? Because it's all stored on the GPU the only two options I've seen is to do the same maths as you use generate the waves but obviously only for the 4 floating locations, or, to access the vertex buffer, but I've read this is very slow and also there's conflicting information about whether this buffer gives you the post shader positions or non manipulated positions. It would be awesome if you could point me in the right direction for this!

    • @tomweiland
      @tomweiland  Год назад

      _"I'm wondering how you get your vertex data back out of the shader and into a C# script?"_
      I don't. I use the first option you mentioned-I just use the same math as in the shader to calculate heights on the CPU as needed.

    • @seancashman4084
      @seancashman4084 Год назад +1

      @@tomweiland Any chance you could show us how? It's doing my head in

  • @ChrisHansonDev
    @ChrisHansonDev 2 года назад

    Awesome tutorial!

  • @whidzee
    @whidzee 3 года назад

    looking really good. how would you go about adding onshore waves around your island?

    • @tomweiland
      @tomweiland  3 года назад +1

      This is something I've actually been working on in my own project over the last couple days, and I'll be talking about how I did that in my next devlog, so keep an eye out for that :)

    • @whidzee
      @whidzee 3 года назад

      @@tomweiland oh very cool. I am looking forward to it. I'm wondering if it's similar to the approach the War Thunder devs used. developer.download.nvidia.com/assets/gameworks/downloads/regular/events/cgdc15/CGDC2015_ocean_simulation_en.pdf

    • @tomweiland
      @tomweiland  3 года назад

      It's definitely nowhere near as complex/in-depth. I pretty much just decreased wave height around islands-it's not entirely realistic but it has the effect I need.

  • @spacearchie2251
    @spacearchie2251 2 года назад

    Hi Tom , nice tutorial :). In the end you say that you use a shader for the wave mesh. How do you get the mesh hight at the boat position from the shader deformed mesh?

    • @tomweiland
      @tomweiland  2 года назад

      I don't get the height _from_ the shader, I just use the same equation that the shader uses to calculate the height for the specific points where I need it.

  • @phee3D
    @phee3D 3 года назад +1

    hey tom, quick question: Are you using URP in your own game? if so then did you write a completely new shader for your water including the lighting? The problem I'm facing is that URP seems to not have the option to create a new "Standard surface shader", instead it creates one in cglanguage for the built in renderer. Which forced me to just create a completely new shader in HLSL but I would love to avoid having to write all the lighting code. Any thoughts on this? Is there some way to use unity's physically based lighting within my custom urp shader (without shader graph)?

    • @tomweiland
      @tomweiland  3 года назад

      Yes, I'm using URP.
      Shader Graph is the only way to automatically use URP's lighting (that I'm aware of), and I think it's intended as the alternative to surface shaders. Since Shader Graph still doesn't allow you to modify certain things that I need to modify, I'm basically just piggy-backing off of URP's shaders. I copy + pasted the code files for the lit shader and then added my extra code, but the drawback is that any time Unity updates or changes something about the lighting calculations, I need to manually update my shaders with that same code for it to take effect.

    • @phee3D
      @phee3D 3 года назад

      @@tomweiland thanks for the info as always. I just created a new lit shader graph and copied its generated code, seems to work fine!

  • @ronniedagan7922
    @ronniedagan7922 2 года назад

    How do we translate the gersther/stacked sin waves into the floater script. I know you said to plug the formula, but the formula of the gersthner waves are more complicated and i cant seem how i can directly plug them in. Great tutorial and i appreciate you responding to so many comments.

    • @tomweiland
      @tomweiland  2 года назад

      You can only get an approximative formula for Gerstner waves (because they move vertices horizontally as well, so using the same formula wouldn't get you the height at the exact point you're looking for), but I think you already found the answer on Discord, right?

  • @austineadah2843
    @austineadah2843 2 года назад

    Nice turorials. I'm very new to opengl and unity.i was thinking isn't there a way to do this with just c++ and opengl and glfw alone?
    Thanks in advance

    • @tomweiland
      @tomweiland  2 года назад

      Probably, but I'm the wrong person to ask. I don't have any experience with C++ or OpenGL.

  • @imadsaddik
    @imadsaddik Год назад

    Thank you my friend

  • @jzoo1614
    @jzoo1614 2 года назад

    Amazing stuff! This low-poly ocean animation & floating effect was exactly what I was looking for for my project. One question though, since my project is using threejs to do all the rendering on web browser instead of unity, do you think this entire approach would also be applicable to threejs/webgl?
    thanks!

    • @tomweiland
      @tomweiland  2 года назад

      I don't know anything about threejs but I don't see why it wouldn't work outside of Unity as long as you replace anything Unity-related with some sort of equivalent.

  • @aexmil7750
    @aexmil7750 Год назад

    love your videos !

  • @ItsVanAken
    @ItsVanAken 4 года назад

    Thanks so much for the help Tom. I went ahead and followed the Catlike tutorial to make Gerstner waves, but am having trouble connecting the WaveManager and Floater script to work with those waves. Any tips?

    • @tomweiland
      @tomweiland  4 года назад +1

      Yeah, unfortunately there's no mathematical formula that will return the height at any given point of a Gerstner wave, simply because Gerstner waves are generated by shifting vertices on the horizontal plane as well as on the y-axis. The best you can get is ia approximation-I spent a _long_ time trying to derive a formula before I realized that :P
      If you're interested in the exact math, I suggest joining the Discord server (link in description) as it's a lot easier to share and explain code over there.

    • @ItsVanAken
      @ItsVanAken 4 года назад

      @@tomweiland Thanks for your help Tom. I'll join the Discord and try to find an answer :)

  • @neylz_
    @neylz_ Год назад

    Hey, just found your vid in my recommendations! you are saying at the end that in your project you are using Gerstner waves, but how do you get the wave height at coordinates XY (considering Z-up sorry i'm unfamiliar with unity) on the CPU side ?

    • @tomweiland
      @tomweiland  Год назад

      I just use the same formula on the CPU side, although it's a bit less straightforward and requires some approximation with the Gerstner wave formula since it doesn't give you the height for the point you used as the input (Gerstner waves move horizontally as well as vertically, so the returned height is for the shifted point, not the original one).

    • @neylz_
      @neylz_ Год назад

      @@tomweiland okay I see, thanks for your answer! Because I’m in a case where my mesh is really large compared to the size of the boats, that’s why i was looking for the formula giving directly the height

  • @457Deniz457
    @457Deniz457 4 года назад +2

    :O Nice :)
    And yes it "was" to bouncy^^

    • @tomweiland
      @tomweiland  4 года назад +1

      Thanks :D

    • @457Deniz457
      @457Deniz457 4 года назад

      @@tomweiland We have to thank you 🤗.

  • @MrBoBrilO
    @MrBoBrilO 4 года назад

    Thank you, great tutor as usual!

  • @wesleycoomans1433
    @wesleycoomans1433 4 года назад +2

    Next shader tutorial 😇

    • @tomweiland
      @tomweiland  4 года назад +1

      I specifically linked the Catlike Coding article to _save_ myself from that, and now here you are, asking for it 😂

    • @wesleycoomans1433
      @wesleycoomans1433 4 года назад

      @@tomweiland im aware of site for years but examples only go so far

    • @tomweiland
      @tomweiland  4 года назад +2

      @@wesleycoomans1433 "examples only go so far" but you want me to provide an example...?

  • @lipysak
    @lipysak 3 года назад

    Hi :-) Nice tutorial! Thanks! How can you make that ship smooth for turning right/left?

    • @tomweiland
      @tomweiland  3 года назад

      You should be able to just use AddTorque to add a rotational force.

  • @surenmelkonyan1240
    @surenmelkonyan1240 3 года назад

    ooh, singleton in FixedUpadate !

  • @WinDArtArh
    @WinDArtArh 3 года назад

    Awesome, thanks!

  • @sorenmuller1974
    @sorenmuller1974 3 года назад

    Looks amazing... Can you share the water shader graph ?

    • @tomweiland
      @tomweiland  3 года назад

      It's not a graph-I learned how to write shaders a while back (before shader graph was a thing) and haven't bother picking up shader graph. It's really just displacing the vertices using a formula, but it's also kind of my "secret sauce" so I'm a bit reluctant to share the shader itself :P

  • @moosekng3436
    @moosekng3436 11 месяцев назад

    Very helpful video, I just have one question, After trying the shader implementation the float mechanic doesn't work wanymore, what changes should I make?

    • @tomweiland
      @tomweiland  11 месяцев назад

      You need to make sure you use the same formula for buoyancy as you use in the shader, otherwise they won't match.

    • @Davey198
      @Davey198 8 месяцев назад

      @@tomweiland how can i make this shader with the shader graph?

  • @homerlol9058
    @homerlol9058 3 года назад

    This tutorial is pretty good
    But I was wondering if this can be done with shaders?

    • @tomweiland
      @tomweiland  3 года назад +1

      I talk about shaders at the end of the video.

    • @homerlol9058
      @homerlol9058 3 года назад

      @@tomweiland oh... my bad, thank you!

  • @inversematrix7156
    @inversematrix7156 4 года назад

    thank u,its really helpful.

  • @mynameisxboard
    @mynameisxboard 4 года назад +1

    Nice tutorial! I don't know why but my floaters always fall to 0.0 world space, if I make the waves' amplitude very high I can see they are reacting to it but they don't stay on the mesh. The plane is located on a higher level and is scaled up a lot

    • @tomweiland
      @tomweiland  4 года назад +3

      Don't scale the plane up, it messes with the wave equation.

    • @mbun
      @mbun Год назад

      @@tomweiland Thanls for this great work! As @Lange, my cube sinks to 0 with the same parameters as in the video. My water plane is not scaled but its y position is at 5. No matter what parameter I change from Floater, WaveManager, Rigidbody, the cube does not stick to the Water plane.

  • @papermartin879
    @papermartin879 4 года назад +1

    this is amazing and works really well in my project ngl
    have you found good settings to make your boat not "bouncy" though? I'm having issue with big boats being a bit bouncy
    edit : nevermind, if you're still having issue, try increasing your boat's Rbody's mass, and in the script, multiply the forward & turn speed with the mass

    • @tomweiland
      @tomweiland  4 года назад +1

      I'm glad it's working for you! I was going to suggest increasing your mass (my boat's mass is 500, though it's still somewhat bouncy), but nice work figuring that out yourself :)

  • @weckar
    @weckar 4 месяца назад

    Any advice for having objects settle down quicker? It looks really nice when it's been running for a dozen seconds or so, but there's some extreme splashing to start with no matter what I do; seemingly :/
    And, while at it, any ideas to keep things from flipping over in rough waves?

    • @tomweiland
      @tomweiland  Месяц назад

      Other than playing with the parameters (maybe increasing drag), not particularly 😅

    • @weckar
      @weckar Месяц назад

      @@tomweiland oh right! I resolved it by now by not making the floater points static and instead picking random points in a semi-capsule hull every timestep.

  • @renatusdev
    @renatusdev 4 года назад

    Question though, if you're using Shaders to move the waves, how do you inform the boat script about where the vertices are? I'm assuming you replicate the shader math inside the boat script and then boom?

    • @tomweiland
      @tomweiland  4 года назад +2

      "you replicate the shader math inside the boat script"
      Yep, that's exactly it. As long as you pass the same values to the same formula you should get the same output.