Create a Cup and Fluid Effect in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so recently I had a personal project for creating a VR environment and I made a cabin and I created a bunch of props and one of the things that I had 3d modeled was a mug and I remembered this scene and Wolfenstein the new order and I thought about I was like that liquid effect looks really cool and it also is very simple and I think it's also very effective so I wanted to try and replicate it myself and this is what I came up with so the mug is comprised of two parts the mug obviously in the liquid what I've done though is I child did childhood the liquid mesh to an empty game object and I did that so when I'm rotating it as well as having it move along with the mug it's easier for me to do the rotations and you'll see a little bit more of that in a bit so taking a quick look at the script we have a few game objects up top for the liquid object as well as the mesh and a few values for the speed as well as the difference that we're going to be using for clamping the rotation within the update we're gonna be calling the slosh method as well as doing the rotation for the liquid mesh and that's the childhood object that is attached to the empty game object that I talked about earlier for the liquid match rotation it's relatively self-explanatory we're just using the rotate function of the transform to slowly rotate the object over time and here's a quick example of that rotation in action it's very exciting I know so now we're going to go back and look at the slosh method where we're gonna be taking the inverse rotation of the mug itself and we'll be taking the local rotation of the mug will be then using the quaternion rotate towards using the local rotation of the liquid as well as the inverse rotation that we just created and then we'll be getting the Euler angles of that will be then storing an Euler angle and final rotation and then we'll be clamping those rotations so as you're tipping the mug the internal mesh isn't flying all over the place and then once we've clamped those values we're actually going to be applying it to the local Euler angles of the liquid itself so before moving on to the clamp rotation I also created a more sloshed method for when the liquid would hit the clamp value and would sort of create a bit of a ping pong animation however once I started trying it out in VR didn't work out so I'm gonna leave that out for now so we're gonna go ahead and move on to our clamp rotation method where we are actually clamping the local rotation values and since we're working in local rotation we're always going to get a value between 0 and 360 so here if the value is above 180 I am simply subtracting the difference from 360 meaning in this case our difference is 25 so we're going to be clamping between 335 and 360 but if it's less than that we're going to be clamping between 0 and 25 here we can see the effect much closer and as I turn the mug until the left and to the right you can see that the liquid takes the inverse rotation of the mug but also stays within the claimed values that we established and that's it thanks for watching and I'll see you next time
Info
Channel: Andrew
Views: 33,129
Rating: undefined out of 5
Keywords: unity liquid, unity cup, unity tutorial, unity liquid cup, unity liquid tutorial, unity vive, unity virtual reality, unity vr tutorial, unity drink, unity drink cup, unity vive tutorial, vive, htc vive, wolfenstein liquid effect, wolfenstein coffee train, unity virtual reality tutorial, unity fluid physics, unity fluid, unity, unity drink physics
Id: OBnCd1bzCcw
Channel Id: undefined
Length: 3min 25sec (205 seconds)
Published: Thu Nov 09 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.