How to Create Bouncy Balls, Icy Surfaces and More using 2D Physics Materials in Unity!?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so in this tutorial I'm going to teach you how to use 2D physics materials to create bouncy balls icy surfaces and anything else you can kind of think of so 2D physics materials are used to create different types of surfaces different types of uh physics apply to game objects in a Unity scene so let me just show you what this does so when I hit uh play here you're going to see this ball is going to just infinitely bounce forever it's just going to bounce it's always going to bounce back to the same point on screen and just forever keep bouncing as you can see it'll just keep bouncing back to this position right here that's because we have it set to constantly bounce on just a one 100 so it gets the exact same force from where it is if I was to bring this higher um let's just bring it all the way up here and I let go you can see it's going to fall down all the way from 22 and go all the way back up to 22 and it's going to keep going back down and up there because it's going to apply the same Force it's given and that's the infinitely bouncing ball so let's just stop this quickly turn off the ball and let's go to the slope and block which I've set up here so we have a block and a slope and we have physical for both of these um the slope actually has no friction meaning it is just going to become like an icy slope and the ball is set to just a default material so let's just hit play and see what happens here so you're going to see the block hits it and slides straight off that's because the slope has no friction whatsoever so let me just delete everything but the ground so let's just delete so we have this ground object it is basically just a Sprite renderer with a square on it and a box collider here I'm going to delete the physics material as well there you go so we are now with a plane scene just so you know we're using Community 2021.3.11 F1 uh if anything changed in the future so if they change physics materials or anything like that I'll try and do an updated video so let's get started by creating a uh let's start with a 2d Circle um which is just going to be our boom I'm just going to reset that so it's in the center we're going to add a uh well we're going to add a rigid body 2D and a circle collider 2D and we're now going to create our first physics material so let me just show you what happens if we hit play on this now this ball is just going to be affected by default gravity hit the ground and stop because it has zero bounciness to it that's not how balls really work they're filled with air and when I hit the ground the air is bounced around inside the ball and Corset to you know bounce all over the place so let's actually create some of that so we're going to create a physics 2D physics material 2D and we're going to call this the bull material now back on the ball we could add this to the um actual material here but because we're using a rigid's body 2D it's actually going to use the rigid bodies material so all we're going to do is we're going to select this and actually apply it to this you can apply it to both if you want but you do not have to now I've noticed some times when using the bounce mechanic if we don't set this to continuous it may not get the correct value so if you set to bounce to one so if we look here on the physics material we've got a friction of zero and a bounciness now you can set this as high as you want if you set this to five every time it bounces it's going to get five times higher than it was before and that's basically just saying we're multiplying it by five one means we're just going to multiply it by one so whatever the forces when it hits this it's going to multiply that force and apply it back we're just going to send it straight back to the same point um and there you go so we don't have to change the friction at all for this it doesn't matter if there's loads of friction or little friction it doesn't work so the default friction immunity is 0.4 so I just leave it that one Crown bouncy balls um now here you can see this is that um and this is basically how you set up so let's have a look what this will do so let's hit let's hit play and this ball is just going to bounce infinitely back to the same spot over and over again and it will just keep doing that until basically you stop the game or you hit with something else you pin it down I don't know how if you want to do that but let's say we don't want it to bounce like that because that's not how bouncy balls work in real life there's a bunch of different factors that slow it down and it won't bounce infinitely um so let's say we set this to let's say 0.8 that means every single time it bounced it's only going to bounce 80 off its original height so when we bounced it the first time it's going to come to about here second time third time time and finally it will just no longer bounce it'll come to almost a complete stop so you can see here bounce bounce bounce bounce and let's go do that little boom boom good so it comes to a complete stopping there you go you can see that's no longer changing the value there that's now stopped completely and you can see the different type of the different ways that actually affects it and we can mess around with this we can set this to like 0.2 so let's say you have let's say what a lot of cricket ball which doesn't have too much bounce because it's quite hard um let's just hit that asset bounds it just hits it hits the ground it's just a little bounce and then stops so you've kind of got that softball there let's set this to two now and we'll go back set this to two and then it's actually hit play and this should now bounce Two Times Higher and if we go to the scene here you're going to see it's going to keep bouncing and bouncing higher on high so now it goes to there next time it will probably be all the way up here and there you go oh it's kind of even higher because it's doubling the amount of Bounce you had last time so even though it was here it then doubled it again so we can mess around with this so let's say if you want it to Incline slowly you could do something like 1.05 and that should slowly get bigger and bigger and bigger the bounce so it goes to there and then there and this should slowly if we go to the ball you'll see this goes slowly above one so that's 1.3 and as you can see it's getting higher and high it's almost touching the roof and it will just keep on going it'll keep adding that .05 to the bounce every single time look it's about to go off screen now and there you go so you can see how that affects it so that is the um how you create like the bounciness and how you use the bounce what about friction so you could apply friction to this ball it's not going to do too much for this case it's only bouncing straight down but if you're bouncing at an angle and you apply more friction then it's going to lose some of that bounce so let's say let's Zoom back in let's say you bounce a ball and you go this way and you have a high friction when it hits that it's not going to bounce as far that way however if you set this to zero it might even slide as it hits and bounce away but another way we can do this is let's say we duplicate the ground quickly let's change this to a site called the slope um let's turn off our ball for this example uh let's put this down to five and there's minus 3.5 um so there you go we've got all just free there you go so we now have a slope here now so we have a slope and let's rotate on the set axis just a little bit or you know let's let's rotate it quite let's see let's do 20. there you go so that's quite High let's then get a square so if we use a ball it doesn't matter how much friction we apply it will always roll because it's a circular object unless we froze the rotation on the set axes so the best way to show you how the slope or the um the friction would work is by using a square because squares do not actually um they don't they're not round and when they hit that flat surface they're going to not slide around so let's call this the block um now on our slope we want to create a new uh physics material 2D so let's create a 2d physics material and call this the slope material now we've got not going to have any bounciness on this slope this slope doesn't actually bounce at all it doesn't have any sort of uh bouncy properties um and it's not like a trampoline it's we're not just planning to make this a bouncy surface so what we want to do is actually add friction so we're going to set the friction to about one here and with the block we're just going to add a box collider 2D and also a rigid body 2D now we're not actually going to add anything else to this or from research transform and let's just hit play and see what happens oh did we forgot to apply the actual slope material here so don't forget to do that so here we go let's hit play this goes down and you can see it kind of rolls but it doesn't slide off now let's go back to the slope material let's turn this down let's say 0.4 let's hit play Let's see what happens when it hits that it still slides and you can see it actually slides off the platform because the friction is less so that is kind of how you create that sort of slide now let's say we do a lot less let's say we have more of an ice effects let's change the rotation off our slope to sync a lot more like five so you can see there it's only a small surface now if we go back to our slope and we set this to 0.4 like the default and the actual block um the block doesn't have a material so let's just hit play now as this falls down you can see it slides a little bit it literally stops basically after well a minute a couple of milliseconds there um which is fine if we go back to our slope and we lower this let's say 0.2 now and let's hit play let's see where it ends up here you can see it again didn't slide too much uh but now let's set this to zero so this is going to have no friction at all however the block will have a little bit of friction but when it hits this slope you're going to see it's infinitely sliding off because friction multiplies to friction so if this has this we'll have by default 0.4 friction but this has zero so four multiplied 0.4 multiplied by zero is still zero so you can see here it just slides right off e for notes only a slight slant and really it shouldn't really do that but because it's this more of an ice texture you've got no uh no bounciness no frictions you get this cold ice off slidy feel there so let's do that again just so you can see that sort of Animation happen it hits that and it's slow slowly slides off it gets faster and faster actually we take this slope and let's just make it tense it's a bit wider and move it on the X to let's say minus three there you go so now let's just Watch What Happens here and we'll go to the scene view just because you can see it gets faster faster faster until it's thrown completely off the map and that's just because there's no friction so it's just getting multiplied it's forced it's gravity and it's mass at times to move it straight down here and off the side um and that's kind of how um the basically physics materials basically just allow you to change how the the the surface of the object reacts to other surfaces now you can add let's say we can make a bouncy platform here we could change this slope to be um a bouncy platform so we can set this to zero and make the slope a bouncy platform so let's say this is 0.4 or set the friction both these 0.4 the block however is going to have no bounciness so when this comes down it's just going to hit that and bounce a little bit because this is more um as I said it has some of the bouncy this let's change this to one hit play and you're going to see this now becomes another infinite bouncing platform so it's kind of like a trampoline um as it hits it it bounces it back um and there you go that'll slowly change you could do this more for like a zero point a to give that sort of if you drop like a rock on a trampoline it would bounce bounce and then slowly get less and less and less until it comes to a complete stop um and there you go so here's a little experiment you can see here I'm doing if I just stop this hitch play uh we're gonna see this all happening these are bouncing into each other causing some weird sort of bounciness there and they finally came to a stop the ball is set to so here's the different things there so both sets are the same 0.4 uh 0.8 but let's swap these around let's move the block and put this to mine outside two and the ball just to zero and see what happens if we do it this way around and there you go you get the same sort of thing um that's very well balanced um normally this would probably tip over but because it's perfectly center it's kept it straight but there you go you see the same sort of effect there because it's just happening the same way because these are both bouncy you get that sort of that bounces that back up in the air until they both come down to a complete stop and there you go so that is that is how you use physics materials you can mess around with these settings change them completely how you want to create different types of surfaces let's say you have a really gritty roads um that's harder to drive from than normal ones you can change this to apply that sort of friction to your objects um if you want a really bouncy castle style area in your game you can up the bounciness um lower the friction so it's a slippery bouncy castle you could do all of those things inside of UT try it all out mess around with the fish materials let me know what you guys create with it in the comments down below but guys that's gonna be it for this tutorial I hope you enjoyed this super simple uh basic hopefully I explained I think as best I could um but yeah I hope you've enjoyed this video if you have don't forget leave a thumbs up smash that subscribe button and I will see you in the next video peace
Info
Channel: Muddy Wolf
Views: 27,135
Rating: undefined out of 5
Keywords: 2d game dev, game dev, 3d game dev, 3d, 2d, game development, developer, game developer, unity, unity3d, unity 2d
Id: UuzmU_lwk2s
Channel Id: undefined
Length: 13min 54sec (834 seconds)
Published: Mon Nov 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.