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

  Рет қаралды 170,432

Tom Weiland

Tom Weiland

4 жыл бұрын

In this tutorial you'll learn how to set up boat movement and dynamic water physics in Unity.
Check out my devlogs: • Multiplayer Pirate Gam...
⎯⎯⎯⎯⎯⎯
Catlike Coding's article about shader-based vertex manipulation and Gerstner waves: catlikecoding.com/unity/tutor...
Discord server: tomweiland.net/discord
Support me on GitHub Sponsors: github.com/sponsors/tom-weiland
Support me on Ko-fi: tomweiland.net/kofi
GitHub: tomweiland.net/github
Website: tomweiland.net/
⎯⎯⎯⎯⎯⎯
In this buoyancy tutorial, we set up dynamic water physics and boat movement in Unity. We'll be making objects float and implementing physics based buoyancy for large objects like ships. While the core of the video is about buoyancy and flotation, setting up boat movement after watching this tutorial is as simple as applying a local forward force. Add some input-based rotational forces to the mix, and you've made a boat controller in Unity!
#UnityTutorial #WaterPhysics #Unity3D #Buoyancy #GameDev
"Interplanetary Forest" by Meydän is licensed under a Creative Commons Attribution license (creativecommons.org/licenses/...)
Artist: / meydansound

Пікірлер: 701
@tomweiland
@tomweiland 4 жыл бұрын
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 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
the probleme was i scaled the plane up.
@JamesOfToya
@JamesOfToya 2 ай бұрын
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 11 күн бұрын
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 🤷‍♂️
@NeatGames
@NeatGames 4 жыл бұрын
I love the way the water moves and looks with the lowpoly look!
@tomweiland
@tomweiland 4 жыл бұрын
Thank you :D
@toluyole
@toluyole 3 жыл бұрын
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 жыл бұрын
Glad you liked it that much :D
@SnutiHQ
@SnutiHQ 3 жыл бұрын
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 3 жыл бұрын
This is awesome to hear, I'm glad you found it helpful! Good luck with the voting phase, assuming that hasn't concluded yet :)
@sharkycat1096
@sharkycat1096 4 жыл бұрын
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 :)
@rogeriocruz658
@rogeriocruz658 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
@tomweiland
@tomweiland 4 жыл бұрын
Glad I could help!
@editingstuff575
@editingstuff575 4 жыл бұрын
Dude, this is really good and informative. You definitely deserve more
@tomweiland
@tomweiland 4 жыл бұрын
Thanks, I really appreciate that!
@mattshu
@mattshu 2 жыл бұрын
I love your style. Easy to comprehend as you code while speaking.
@tomweiland
@tomweiland 2 жыл бұрын
Glad you like it :D
@Marcos10PT
@Marcos10PT 3 жыл бұрын
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 3 жыл бұрын
Glad you liked it :D
@Marcos10PT
@Marcos10PT 3 жыл бұрын
@@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.
@e.d.gproductions7989
@e.d.gproductions7989 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 жыл бұрын
Glad I could help :)
@IWEKNOWI
@IWEKNOWI 2 ай бұрын
я тоже хочу, научиться и сделать, что то кроме синусоидальных волн, а именно как в lowpolywater. но не умею, хотелось бы знать как!
@tomasbenders922
@tomasbenders922 4 жыл бұрын
Not planning to use this any time soon, but damn that was a good and simple tutorial!
@tomweiland
@tomweiland 4 жыл бұрын
Thank you :D
@onelonewolf2944
@onelonewolf2944 4 жыл бұрын
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.
@tomweiland
@tomweiland 4 жыл бұрын
Glad you liked it!
@RazixStyle
@RazixStyle 4 жыл бұрын
Great video Tom! Cant wait for the next one
@tomweiland
@tomweiland 4 жыл бұрын
Thanks :D
@mohitsethi99
@mohitsethi99 4 жыл бұрын
Your channel is treasure! Really good tutorials, keep it up!
@tomweiland
@tomweiland 4 жыл бұрын
Thank you :D
@Quinthelas
@Quinthelas 2 жыл бұрын
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.
@tomweiland
@tomweiland 2 жыл бұрын
Glad I could help :)
@narwhalgamingvariety
@narwhalgamingvariety 6 ай бұрын
Incredibly good tutorial, I was looking for simple arcade buoyancy and this did the job right away!
@tomweiland
@tomweiland 6 ай бұрын
Glad you like it!
@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 3 жыл бұрын
@@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.
@waasar
@waasar Жыл бұрын
This is a great tutorial for quickly getting into the good stuff. Thanks!
@tomweiland
@tomweiland Жыл бұрын
Glad you like it :)
@renatusdev
@renatusdev 4 жыл бұрын
Tom The Man! Thank you bro, using this immediately rn. You got a sub!
@tomweiland
@tomweiland 4 жыл бұрын
Glad you liked it, and welcome to the community :)
@trolleycartwheel9409
@trolleycartwheel9409 Жыл бұрын
Thank you for this, I was also looking for tutorias like this for quite a while.
@tomweiland
@tomweiland Жыл бұрын
Glad it was helpful!
@richardstevenson371
@richardstevenson371 3 жыл бұрын
I wanted to start working on a naval trading/exploration game myself, and this is amazing. : ) Subscribed my friend.
@tomweiland
@tomweiland 3 жыл бұрын
Glad you liked the videos-welcome to the community :)
@DunnV89
@DunnV89 3 жыл бұрын
How this game coming along?? I only ask because it sounds a lot like what I’m trying to create.
@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 😂
@SteveTheExploiter
@SteveTheExploiter 4 жыл бұрын
Thank you! This was VERY informative!
@tomweiland
@tomweiland 4 жыл бұрын
I'm glad you think so!
@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
@carny666
@carny666 3 жыл бұрын
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 3 жыл бұрын
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
@digital_gaming8568
@digital_gaming8568 3 жыл бұрын
This is an amazing tutorial i learned exactly what i needed
@tomweiland
@tomweiland 3 жыл бұрын
Glad to hear it :)
@Hazzel31337
@Hazzel31337 Жыл бұрын
awsome thank you, quick, packed with information, easy to understand and follow
@tomweiland
@tomweiland Жыл бұрын
Glad you liked it :)
@xavmanisdabestest
@xavmanisdabestest 3 жыл бұрын
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
@fabianvelander
@fabianvelander 4 жыл бұрын
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
@MrBoBrilO
@MrBoBrilO 4 жыл бұрын
Thank you, great tutor as usual!
@tomweiland
@tomweiland 4 жыл бұрын
Thanks :)
@maxtoka5867
@maxtoka5867 6 ай бұрын
Finally helpful guide.
@tomweiland
@tomweiland 6 ай бұрын
Glad it was helpful :)
@Hero.S
@Hero.S 8 ай бұрын
I love your water dude it is so cool
@tomweiland
@tomweiland 8 ай бұрын
Thanks :)
@deathcoredude6565
@deathcoredude6565 3 жыл бұрын
don't understand most of it so far but this is phenomenal to me, awesome job! :D
@tomweiland
@tomweiland 3 жыл бұрын
Glad you like it :)
@aexmil7750
@aexmil7750 Жыл бұрын
love your videos !
@tomweiland
@tomweiland Жыл бұрын
Thanks :D
@ThePoinball
@ThePoinball 4 жыл бұрын
Awesome ! thanks for this good knowlege !
@tomweiland
@tomweiland 4 жыл бұрын
Thanks, I'm glad you've found it useful :)
@ajaykumar-qw3qr
@ajaykumar-qw3qr 3 жыл бұрын
Awesome Tutorial. I will try it Now. Thank you .
@tomweiland
@tomweiland 3 жыл бұрын
Good luck :)
@frankzander5946
@frankzander5946 3 жыл бұрын
absolutely awsome :-) just what the doctor prescribed! Many thx!
@tomweiland
@tomweiland 3 жыл бұрын
Glad it was helpful!
@decidev
@decidev 2 жыл бұрын
Damn bro you thought of everything! Super helpful for my project! Thanks!
@tomweiland
@tomweiland 2 жыл бұрын
Glad to hear it :D
@magnusm4
@magnusm4 3 жыл бұрын
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 жыл бұрын
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
@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 :)
@RugbugRedfern
@RugbugRedfern 4 жыл бұрын
Ooh, a new series!
@tomweiland
@tomweiland 4 жыл бұрын
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)?
@Spamap
@Spamap 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
@@tomweiland Ok, thanks!
@FERRRU
@FERRRU 3 жыл бұрын
thankyou tom weliand
@tomweiland
@tomweiland 3 жыл бұрын
Glad I could help!
@ChrisHansonDev
@ChrisHansonDev Жыл бұрын
Awesome tutorial!
@tomweiland
@tomweiland Жыл бұрын
Glad you liked it!
@youneskasdi
@youneskasdi 3 жыл бұрын
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 жыл бұрын
I love the low poly look as well. Sometimes I feel like I could just gaze at it for hours :P
@imadsaddik
@imadsaddik Жыл бұрын
Thank you my friend
@tomweiland
@tomweiland Жыл бұрын
You're welcome :)
@keventy6114
@keventy6114 4 жыл бұрын
This is awesome. Could probably link this up to some type of stormy sea/weather system
@tomweiland
@tomweiland 4 жыл бұрын
For sure! I'll be doing that at some point in my own project.
@lordpickle6442
@lordpickle6442 2 жыл бұрын
Great tutorial. Sure, The World Wide Web Is Great, But You, You Make Me Salivate.
@tomweiland
@tomweiland 2 жыл бұрын
I don't know what to do with this information 😳
@inversematrix7156
@inversematrix7156 4 жыл бұрын
thank u,its really helpful.
@tomweiland
@tomweiland 4 жыл бұрын
Glad to hear that!
@WinDArtArh
@WinDArtArh 3 жыл бұрын
Awesome, thanks!
@tomweiland
@tomweiland 3 жыл бұрын
Glad you liked it :)
@brandon-leecoskey5942
@brandon-leecoskey5942 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@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 3 жыл бұрын
@@brandon-leecoskey5942 ah right, I always forget people use shader graph-I still write all my shaders with code :P
@WhatShouldIWatch
@WhatShouldIWatch 3 жыл бұрын
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 3 жыл бұрын
Good point-a few people have run into that issue.
@Quinthelas
@Quinthelas 2 жыл бұрын
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 10 ай бұрын
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 10 ай бұрын
Double check that the RigidBody is filled in the editor. For some reason the reference removes itself.@@ethancotton1549
@akinmustafa
@akinmustafa 4 жыл бұрын
Good tutorial, keep going
@tomweiland
@tomweiland 4 жыл бұрын
Thank you, I will!
@samueladlard5754
@samueladlard5754 2 жыл бұрын
The water in his game is the most satisfying thing to watch
@tomweiland
@tomweiland 2 жыл бұрын
Glad you like it 😅
@davegorbik1033
@davegorbik1033 4 жыл бұрын
thanks the video really helped :)
@tomweiland
@tomweiland 4 жыл бұрын
Awesome :D
@sleepykittyMMD
@sleepykittyMMD 7 ай бұрын
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😅
@tomweiland
@tomweiland 7 ай бұрын
Good luck :)
@peterthompson8484
@peterthompson8484 4 жыл бұрын
Awesome!
@tomweiland
@tomweiland 4 жыл бұрын
Thanks :D
@lordest
@lordest 3 жыл бұрын
Very good!!!
@tomweiland
@tomweiland 3 жыл бұрын
Thanks :)
@munyunu
@munyunu Жыл бұрын
Perfect amount of simplicity and actually great results that make sense.
@tomweiland
@tomweiland Жыл бұрын
Glad you liked it :)
@wolfsdendogsanctuary731
@wolfsdendogsanctuary731 4 жыл бұрын
Thank you very much :D
@tomweiland
@tomweiland 4 жыл бұрын
You're welcome!
@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 жыл бұрын
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 жыл бұрын
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!
@457Deniz457
@457Deniz457 4 жыл бұрын
:O Nice :) And yes it "was" to bouncy^^
@tomweiland
@tomweiland 4 жыл бұрын
Thanks :D
@457Deniz457
@457Deniz457 4 жыл бұрын
@@tomweiland We have to thank you 🤗.
@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 жыл бұрын
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: kzfaq.info/get/bejne/l7uXldd5s6_TYZ8.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.
@Maskeowl
@Maskeowl 5 ай бұрын
love it
@tomweiland
@tomweiland 4 ай бұрын
:)
@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 жыл бұрын
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 :)
@Whatabaws117
@Whatabaws117 3 жыл бұрын
great stuff
@tomweiland
@tomweiland 3 жыл бұрын
Thank you, glad I could help :)
@raffantt
@raffantt 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 жыл бұрын
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 😅
@raffantt
@raffantt 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!
@marysheridan352
@marysheridan352 4 жыл бұрын
Thanks man
@tomweiland
@tomweiland 4 жыл бұрын
You're welcome!
@ahmetomercicek5848
@ahmetomercicek5848 Жыл бұрын
thanks mate
@tomweiland
@tomweiland Жыл бұрын
👍
@greenfigure3941
@greenfigure3941 4 жыл бұрын
epic now i can recreate your game before you release yours
@duthcgamerking
@duthcgamerking 4 жыл бұрын
hehe typical mr.krabs practices :P
@tomweiland
@tomweiland 4 жыл бұрын
You can try :P
@fernandocabal5798
@fernandocabal5798 2 жыл бұрын
Where is your game ?
@ryanevertz8455
@ryanevertz8455 Жыл бұрын
@@fernandocabal5798 lol
@setseretze3565
@setseretze3565 3 жыл бұрын
wow u have more cool tuts might sub
@tomweiland
@tomweiland 3 жыл бұрын
Thanks 😅
@adiletmyrzabekov6298
@adiletmyrzabekov6298 3 жыл бұрын
Thanks bro / best one
@tomweiland
@tomweiland 3 жыл бұрын
Glad I could help :)
@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.
@amongthecouch23
@amongthecouch23 Жыл бұрын
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 Жыл бұрын
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 😅
@delcraft7709
@delcraft7709 2 жыл бұрын
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 жыл бұрын
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.
@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 😀)
@tomweiland
@tomweiland 3 жыл бұрын
Glad you like my content :D
@farhanhakim2189
@farhanhakim2189 3 жыл бұрын
@@tomweiland yea
@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.
@AlexisPAUTROT
@AlexisPAUTROT 3 жыл бұрын
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 3 жыл бұрын
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.
@phee3D
@phee3D 3 жыл бұрын
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!
@sofusstuff
@sofusstuff 3 жыл бұрын
Hey, I have a question about the shader tutorial you linked in the description. I just started trying to follow it, but as soon as I made the shader material, it just turned pink without any color. The waves do not work either. What should I do?
@tomweiland
@tomweiland 3 жыл бұрын
Have you completed the entire shader? Pink means there's an error, which may occur if it's incomplete. If you're using URP then the issue is probably that the shader from the article is made for the built-in render pipeline, which isn't compatible with URP. You'll have to convert it, which will be hard if you don't know much about shaders-it might be easier to recreate in shader graph...
@WTGDarksight
@WTGDarksight 2 жыл бұрын
I know its been a while since you typed this comment but I was wondering if by chance you have any documentation on doing such a thing. Want to get the most performance possible because I am currently developing a vr game and doing it CPU based with blow someones headset up haha
@plokkum
@plokkum 3 жыл бұрын
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 жыл бұрын
I'll give it a shot, although on a theoretical level I'm not convinced :P
@Wisse37
@Wisse37 3 жыл бұрын
Great video! one question: how did you rewrite the formula from the shader to the WaveManager?
@tomweiland
@tomweiland 3 жыл бұрын
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 3 жыл бұрын
@@tomweiland Thanks for the reply, i am in your discord and found other people asking, so i managed to get the formula.
@benjamenkuhman6808
@benjamenkuhman6808 Жыл бұрын
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 8 ай бұрын
Yep helped me as well. In the video, the water drag is multiplied with fixedDelta time but not the gravity calculations
@Fezezen
@Fezezen 3 жыл бұрын
I wrote my own shader for the waves, and I'm using the same formula to get the wave height at any given point, but it's not accurate to the actual height of the waves. I'm thinking this is because of the view matrix math (UNITY_MATRIX_VP) and I'm unsure how to go about fixing this. How did you have the vertex math line up with the wave manager formula in your game?
@Fezezen
@Fezezen 3 жыл бұрын
Nevermind, I found the issue. I was using _Time in my shader instead of _Time.y. So the time value I was using was different.
@tomweiland
@tomweiland 3 жыл бұрын
Glad you solved it!
@surenmelkonyan1240
@surenmelkonyan1240 3 жыл бұрын
ooh, singleton in FixedUpadate !
@tomweiland
@tomweiland 3 жыл бұрын
Uh...what? 😅
@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.
@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 жыл бұрын
"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.
@richardstevenson371
@richardstevenson371 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
​@@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 3 жыл бұрын
@@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 3 жыл бұрын
@@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/
@tomharris4622
@tomharris4622 3 жыл бұрын
Great video Tom, is it possible to put objects, like the player character on the boat without messing with the physics?
@tomweiland
@tomweiland 3 жыл бұрын
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 3 жыл бұрын
@@tomweiland mass was the main issue, increasing that a large amount solved my issue. Thanks
@whidzee
@whidzee 3 жыл бұрын
looking really good. how would you go about adding onshore waves around your island?
@tomweiland
@tomweiland 3 жыл бұрын
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.
@neylz_
@neylz_ 10 ай бұрын
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 10 ай бұрын
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_ 10 ай бұрын
@@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
@Joewa_
@Joewa_ 2 жыл бұрын
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 2 жыл бұрын
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
@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 жыл бұрын
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 :)
@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 Жыл бұрын
@@tomweiland Any chance you could show us how? It's doing my head in
@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.
@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
@mitchwar2065
@mitchwar2065 3 жыл бұрын
I have a big question. Say that I am using Shader Graph to calculate the water displacement with the help of some gradient noise, is there anyway that I could replicate that through script? For now at least I have just approximated the waves using a simple Sine function however I feel as though when I'll implement more complex water, it won't hold up.
@tomweiland
@tomweiland 3 жыл бұрын
You'd have to use the same gradient noise in the script-as long as the formula is deterministic you should be able to just use the same one in the shader and the script and it should work.
@grid4892
@grid4892 4 жыл бұрын
hi, love ur tutorial, can u please make a tutorial on how to make it run on gpu like urs, cause i dont really understood the article too well and i would love to see it in vid format. i think lots of people would too :)
@tomweiland
@tomweiland 4 жыл бұрын
I don't plan on making a tutorial about shaders. I really don't see how it would be different if it's in video form, and I don't want to spend time turning a perfectly good article into a video. If you're struggling to understand the article (although you really just have to copy + paste, and I believe you can download the project files as well), then you should learn some shader fundamentals first, and there's tons of tutorials out there for that.
@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.
Why Making Multiplayer Games SUCKS
6:46
Tom Weiland
Рет қаралды 406 М.
How I Fixed the Ocean in My Pirate Game
6:04
Tom Weiland
Рет қаралды 80 М.
Which one of them is cooler?😎 @potapova_blog
00:45
Filaretiki
Рет қаралды 10 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 21 МЛН
A pack of chips with a surprise 🤣😍❤️ #demariki
00:14
Demariki
Рет қаралды 52 МЛН
Ocean waves simulation with Fast Fourier transform
14:26
Jump Trajectory
Рет қаралды 363 М.
Buoyancy with Unity Rigidbodies - Part 1 / Planar Buoyancy
13:19
V.A. - Indie Dev
Рет қаралды 44 М.
How Games Fake Water
22:52
Acerola
Рет қаралды 191 М.
How Water Works (in Video Games)
8:55
Stylized Station
Рет қаралды 569 М.
how water works in Sea of Thieves
3:25
Stylized Station
Рет қаралды 911 М.
Godot FINALLY Got Better Softbody
2:00
PiCode
Рет қаралды 11 М.
Evolving AIs - Predator vs Prey, who will win?
12:15
Pezzza's Work
Рет қаралды 2,8 МЛН
3 Hours vs. 3 Years of Blender
17:44
Isto Inc.
Рет қаралды 3,7 МЛН
What does a Game Engine actually do?
16:45
Ellie Rasmussen
Рет қаралды 140 М.
Which one of them is cooler?😎 @potapova_blog
00:45
Filaretiki
Рет қаралды 10 МЛН