Тёмный

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

Tom Weiland
Подписаться 31 тыс.
Просмотров 176 тыс.
50% 1

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....
Discord server: tomweiland.net...
Support me on GitHub Sponsors: github.com/spo...
Support me on Ko-fi: tomweiland.net...
GitHub: tomweiland.net...
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 (creativecommon...)
Artist: / meydansound

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 705   
@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 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 года назад
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 5 месяцев назад
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 3 месяца назад
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 7 дней назад
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 года назад
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
@Marcos10PT
@Marcos10PT 4 года назад
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 года назад
Glad you liked it :D
@Marcos10PT
@Marcos10PT 4 года назад
@@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.
@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
@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 :)
@SnutiHQ
@SnutiHQ 4 года назад
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 года назад
This is awesome to hear, I'm glad you found it helpful! Good luck with the voting phase, assuming that hasn't concluded yet :)
@editingstuff575
@editingstuff575 4 года назад
Dude, this is really good and informative. You definitely deserve more
@tomweiland
@tomweiland 4 года назад
Thanks, I really appreciate that!
@WhatShouldIWatch
@WhatShouldIWatch 4 года назад
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 года назад
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 Год назад
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
@mattshu
@mattshu 2 года назад
I love your style. Easy to comprehend as you code while speaking.
@tomweiland
@tomweiland 2 года назад
Glad you like it :D
@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!
@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
@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!
@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 4 месяца назад
я тоже хочу, научиться и сделать, что то кроме синусоидальных волн, а именно как в lowpolywater. но не умею, хотелось бы знать как!
@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 😂
@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
@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 :)
@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
@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
@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 😅
@greatbigeyeball
@greatbigeyeball 9 месяцев назад
Incredibly good tutorial, I was looking for simple arcade buoyancy and this did the job right away!
@tomweiland
@tomweiland 8 месяцев назад
Glad you like it!
@richardstevenson371
@richardstevenson371 4 года назад
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 3 года назад
How this game coming along?? I only ask because it sounds a lot like what I’m trying to create.
@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
@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)?
@samueladlard5754
@samueladlard5754 3 года назад
The water in his game is the most satisfying thing to watch
@tomweiland
@tomweiland 3 года назад
Glad you like it 😅
@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!
@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
@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
@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.
@waasar
@waasar Год назад
This is a great tutorial for quickly getting into the good stuff. Thanks!
@tomweiland
@tomweiland Год назад
Glad you like it :)
@gloriousptr
@gloriousptr 4 года назад
Your channel is treasure! Really good tutorials, keep it up!
@tomweiland
@tomweiland 4 года назад
Thank you :D
@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
@trolleycartwheel9409
@trolleycartwheel9409 Год назад
Thank you for this, I was also looking for tutorias like this for quite a while.
@tomweiland
@tomweiland Год назад
Glad it was helpful!
@maxtoka5867
@maxtoka5867 8 месяцев назад
Finally helpful guide.
@tomweiland
@tomweiland 8 месяцев назад
Glad it was helpful :)
@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!
@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 :)
@RazixStyle
@RazixStyle 4 года назад
Great video Tom! Cant wait for the next one
@tomweiland
@tomweiland 4 года назад
Thanks :D
@digital_gaming8568
@digital_gaming8568 3 года назад
This is an amazing tutorial i learned exactly what i needed
@tomweiland
@tomweiland 3 года назад
Glad to hear it :)
@decidev
@decidev 2 года назад
Damn bro you thought of everything! Super helpful for my project! Thanks!
@tomweiland
@tomweiland 2 года назад
Glad to hear it :D
@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 :)
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-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.
@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.
@Hazzel31337
@Hazzel31337 Год назад
awsome thank you, quick, packed with information, easy to understand and follow
@tomweiland
@tomweiland Год назад
Glad you liked it :)
@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 11 месяцев назад
Yep helped me as well. In the video, the water drag is multiplied with fixedDelta time but not the gravity calculations
@sleepykittyMMD
@sleepykittyMMD 9 месяцев назад
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 9 месяцев назад
Good luck :)
@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 😳
@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
@munyunu
@munyunu Год назад
Perfect amount of simplicity and actually great results that make sense.
@tomweiland
@tomweiland Год назад
Glad you liked it :)
@ThePoinball
@ThePoinball 4 года назад
Awesome ! thanks for this good knowlege !
@tomweiland
@tomweiland 4 года назад
Thanks, I'm glad you've found it useful :)
@SteveTheExploiter
@SteveTheExploiter 4 года назад
Thank you! This was VERY informative!
@tomweiland
@tomweiland 4 года назад
I'm glad you think so!
@frankzander5946
@frankzander5946 3 года назад
absolutely awsome :-) just what the doctor prescribed! Many thx!
@tomweiland
@tomweiland 3 года назад
Glad it was helpful!
@FERRRU
@FERRRU 3 года назад
thankyou tom weliand
@tomweiland
@tomweiland 3 года назад
Glad I could help!
@ajaykumar-qw3qr
@ajaykumar-qw3qr 3 года назад
Awesome Tutorial. I will try it Now. Thank you .
@tomweiland
@tomweiland 3 года назад
Good luck :)
@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 🤗.
@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.
@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 года назад
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 года назад
@@brandon-leecoskey5942 ah right, I always forget people use shader graph-I still write all my shaders with code :P
@Hero.S
@Hero.S 11 месяцев назад
I love your water dude it is so cool
@tomweiland
@tomweiland 11 месяцев назад
Thanks :)
@aexmil7750
@aexmil7750 Год назад
love your videos !
@tomweiland
@tomweiland Год назад
Thanks :D
@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 года назад
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 года назад
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 :)
@MrBoBrilO
@MrBoBrilO 4 года назад
Thank you, great tutor as usual!
@tomweiland
@tomweiland 4 года назад
Thanks :)
@ChrisHansonDev
@ChrisHansonDev 2 года назад
Awesome tutorial!
@tomweiland
@tomweiland 2 года назад
Glad you liked it!
@imadsaddik
@imadsaddik Год назад
Thank you my friend
@tomweiland
@tomweiland Год назад
You're welcome :)
@AlexisPAUTROT
@AlexisPAUTROT 4 года назад
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 года назад
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.
@Zarksch
@Zarksch Год назад
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 Год назад
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): ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kGEqaX4Y4bQ.html
@Zarksch
@Zarksch Год назад
@@tomweiland Thank you for that very quick and great answer even thpugh this is an older video !:))
@papermartin879
@papermartin879 4 года назад
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 года назад
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 2 месяца назад
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?
@BearCavalryWasTaken
@BearCavalryWasTaken Год назад
I know this is a few years old but I am using it now, I am having an issue where if the object gets bellow the water at all it'll stop floating and just sink into the void
@tomweiland
@tomweiland Год назад
It may just be that you need to play around with the floater values more to make it more buoyant. If that doesn't work, join the Discord server and ask about it there :)
@wesleycoomans1433
@wesleycoomans1433 4 года назад
Next shader tutorial 😇
@tomweiland
@tomweiland 4 года назад
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 года назад
@@wesleycoomans1433 "examples only go so far" but you want me to provide an example...?
@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
@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.
@WinDArtArh
@WinDArtArh 3 года назад
Awesome, thanks!
@tomweiland
@tomweiland 3 года назад
Glad you liked it :)
@LemonProductionsPL
@LemonProductionsPL 2 года назад
Eyo question , how could i make it so when i go to a specific place and click button to interact with it so the player could control the boat???
@tomweiland
@tomweiland 2 года назад
You'll probably want to use raycasts or trigger colliders to ensure the player is in the correct area, and then just check if they press the interact button.
@LemonProductionsPL
@LemonProductionsPL 2 года назад
@@tomweiland thx so much
@inversematrix7156
@inversematrix7156 4 года назад
thank u,its really helpful.
@tomweiland
@tomweiland 4 года назад
Glad to hear that!
@kouni.i
@kouni.i 4 года назад
Nice
@tomweiland
@tomweiland 4 года назад
The video has been out for one minute-how is that enough time to make a verdict 😂
@kouni.i
@kouni.i 4 года назад
@@tomweiland it was just what was i looking for xD
@tomweiland
@tomweiland 4 года назад
@@kouni.i that's awesome to hear! Did you find it in search or was it suggested to you?
@kouni.i
@kouni.i 4 года назад
@@tomweiland Notification popped out, because im subbed to you since Dani's video
@tomweiland
@tomweiland 4 года назад
@@kouni.i sounds like a happy coincidence then!
@finalrenderanimationstudio
@finalrenderanimationstudio 3 года назад
"Whheeeeee, weeeeeee, whheeeee Loopty loop!" 6:16
@tomweiland
@tomweiland 3 года назад
😅
@finalrenderanimationstudio
@finalrenderanimationstudio 3 года назад
@@tomweiland I really enjoyed the tutorial tho lol... Keep on dev logging too! You're doing great!
@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.
@blanketparty5259
@blanketparty5259 Год назад
Damn I got to the end and you said its not optimized xD I also went to that document to handle it on the gpu and it looks like rocket science x(
@tomweiland
@tomweiland Год назад
It may look that way if you've never done any shader programming, but it _is_ a step by step guide so you don't really need prior experience.
@thepotatopeel6478
@thepotatopeel6478 3 года назад
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 года назад
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.
@LudicBrainwaves
@LudicBrainwaves 6 месяцев назад
This a speed run tutorial or are we suppose to drop the video speed down to less then 50% to see what you're doing?
@tomweiland
@tomweiland 6 месяцев назад
I left plenty of time to pause between steps, which in my experience is what you end up doing anyways when watching a tutorial. This way you at least get to see the next step in full quicker instead of having to skip ahead because it's SOOO slow :P
@williamcourchane3135
@williamcourchane3135 4 месяца назад
I did the same thing. 50%
@ivanakarain1532
@ivanakarain1532 Год назад
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.
@Joewa_
@Joewa_ 3 года назад
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
@Jawsarn
@Jawsarn Год назад
Great stuff but I don't think the subdivison of gravity is necessary and infact even correct depending on the object shape you're working with as you want to apply gravity at "center of gravity" and not necessarily center of floaters. Using the base gravity should be correct here from my understanding.
@tomweiland
@tomweiland Год назад
I did it that way to address situations where one side of an object is submerged while the other side is not, but now that I think about it you may be right about it being unnecessary-I wonder if not "splitting" the gravity among the floaters would make any noticeable difference on how it looks 🤔
@akinmustafa
@akinmustafa 4 года назад
Good tutorial, keep going
@tomweiland
@tomweiland 4 года назад
Thank you, I will!
@P1xelatedY
@P1xelatedY 18 дней назад
Im getting this error when I made the WaveManager and Floater at 4:30 can you help me? Assets\Code\Floater.cs(14,46): error CS1026: ) expected
@nurarifmaulana3130
@nurarifmaulana3130 16 дней назад
My ship doesn't float even though everything is the same as in the video
@kingdavegamess
@kingdavegamess 4 года назад
thanks the video really helped :)
@tomweiland
@tomweiland 4 года назад
Awesome :D
@richardstevenson371
@richardstevenson371 4 года назад
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 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/
@Maskeowl
@Maskeowl 8 месяцев назад
love it
@tomweiland
@tomweiland 7 месяцев назад
:)
@lordest
@lordest 3 года назад
Very good!!!
@tomweiland
@tomweiland 3 года назад
Thanks :)
@ahmetomercicek5848
@ahmetomercicek5848 Год назад
thanks mate
@tomweiland
@tomweiland Год назад
👍
@j.isasi_
@j.isasi_ 2 года назад
How do I make the shader for the water, I cant manage to do it myself.
@tomweiland
@tomweiland 2 года назад
You can use that article I linked to in the description or you can follow along with one of the many video tutorials that are out there.
@ciaranhappyentriepaw
@ciaranhappyentriepaw 2 года назад
so im having an interesting problem. As far as I could tell, everything worked fine with just a single floater, but when I introduced multiple floaters everything broke. My ship does react with the water, but it seems to be doing it too much. Its spazzing out, is the best way i can describe it. I have fiddled with the rigidbody settings on the ship and sometimes it gets marginally better, sometimes it gets a lot worse, usually nothing noticeable changes. I tested this out with a cube (was originally using a 6th rate frigate model I made, since I already had it and it was more representative than a cube was) and it works fine on the cube, which, in my mind, means that the issue isn't with any of the scripts but is something about the set up on my larger ship. I have no idea what the issue their might be, though. I frankly dont see how the way I have it set up on one ship could possibly break the system to that extent. any ideas?
@ciaranhappyentriepaw
@ciaranhappyentriepaw 2 года назад
I half fixed it. Adding a collider seems to have fixed the problem, for some reason, but the ship is still floating really weirdly. It looks like the gravity aspect of the floaters arent quite working as expected there (The bow and stern remain roughly aligned with each-other, even when they really shouldn't be), so the ships gundeck, and sometimes even the upperworks, regularly get submerged. This isnt a gamebreaking issue, unlike the one that the collider solved, but it is annoying and quite distracting. This is also a problem on the cube i used to debug the prevous issue (I had to scale it significantly for it to actually be noticeable though). I personally suspect I must have gotten something wrong in the floater script somewhere but I wonder if anyone else had this issue?
@tomweiland
@tomweiland 2 года назад
What did you attach a collider to? The water plane shouldn't have a collider attached. How many floaters are you using? If your boat is substantially bigger than that test cube and you're using the same amount of floaters, that's probably the problem. The water height is only check at the position of each floater, so for example if you only have a floater at each corner of the cube/boat, a higher water height halfway between those floaters (aka around the middle of the boat) won't in any way affect the boat's movement. Based on what you're describing, it sounds like you probably need to add more floaters at different positions.
@ciaranhappyentriepaw
@ciaranhappyentriepaw 2 года назад
​@@tomweiland Thanks for the response! The water has no collider - the mother gameobject of the ship (which also has the rigidbody) has a box collider. beneath this object are the floaters and the ships models. I had 7 floaters, which i thought was an alright amount. I now have 14 and the issue persists. The test cube also seems to have this problem, so I dont think floater counts are the issue. I did some testing I also tried giving the floaters colliders - no effect - and rigidbodies - completely broke everything - I finally reenables gravity on the Rigidbody - I dont think that helped but it may be an avenue of investigation. I did realise something, though, my ship tends to list (lean) towards random sides a bit arbitrarily. I didnt think much of this at first since, well, I expected that behaviour, but I did just realise - it might be gravity that is doing that, and if so, then gravity seems to work on the sides, its just the front and back that remain roughly stationary. If this is indeed the case, then could it be a transform issue? Here is my floater script, if it helps. public class Floater : MonoBehaviour { public Rigidbody rigidBody; public float depthBeforeSubmerged = 1f; public float displacementAmount = 3f; public int floaterCount; public float waterDrag = 0.99f; public float waterAngularDrag = 0.5f; private void FixedUpdate() { rigidBody.AddForceAtPosition(Physics.gravity / floaterCount, transform.position, ForceMode.Acceleration); float waveHeight = WaveManager.instance.GetWaveHeight(transform.position.x); if (transform.position.y < waveHeight) { float displacementMultiplier = Mathf.Clamp01((waveHeight - transform.position.y) / depthBeforeSubmerged) * displacementAmount; rigidBody.AddForceAtPosition(new Vector3(0f, Mathf.Abs(Physics.gravity.y) * displacementMultiplier, 0f),transform.position, ForceMode.Acceleration); rigidBody.AddForce(displacementMultiplier * -rigidBody.velocity * waterDrag * Time.fixedDeltaTime, ForceMode.VelocityChange); rigidBody.AddTorque(displacementMultiplier * -rigidBody.angularVelocity * waterAngularDrag * Time.fixedDeltaTime, ForceMode.VelocityChange); } } }
@tomweiland
@tomweiland 2 года назад
Does your water plane have a scale of 1? If not, that'll cause some major problems
@ciaranhappyentriepaw
@ciaranhappyentriepaw 2 года назад
@@tomweiland the water plane does have a scale of 1. At this point I'm considering scrapping the gravity part of the code and figuring out my own solution to create the same general effect, since I'm completely lost as too what I've done wrong. (I do have ideas on how I could do that)
@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!
@WolfsdenxD
@WolfsdenxD 4 года назад
Thank you very much :D
@tomweiland
@tomweiland 4 года назад
You're welcome!
@RandomGuy-df5us
@RandomGuy-df5us 4 года назад
Well that was smart, how long have you been coding to get to that point without any tutorial ._.
@tomweiland
@tomweiland 4 года назад
I started learning when I was 12 (I'm 19 now), so about 7 years, although up until 2-3 years ago it was all super basic stuff.
@RandomGuy-df5us
@RandomGuy-df5us 4 года назад
@@tomweiland i really respect people like you that teaches us new programmers new stuff everyday, keep up the good work
@ahmada1629
@ahmada1629 4 года назад
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 года назад
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?
@Whatabaws117
@Whatabaws117 3 года назад
great stuff
@tomweiland
@tomweiland 3 года назад
Thank you, glad I could help :)
Далее
How Games Fake Water
22:52
Просмотров 207 тыс.
Dear Game Developers, Stop Messing This Up!
22:19
Просмотров 712 тыс.
Why Making Multiplayer Games SUCKS
6:46
Просмотров 423 тыс.
how water works in Sea of Thieves
3:25
Просмотров 916 тыс.
They Dared Me To Make A Game...
12:08
Просмотров 1,1 млн
The biggest lie in video games
15:18
Просмотров 1,9 млн
Do Video Games Fake Buoyancy?
17:08
Просмотров 232 тыс.
Simple Liquid Simulation in Unity!
15:46
Просмотров 133 тыс.
How I Fixed the Ocean in My Pirate Game
6:04
Просмотров 82 тыс.