How To Make A 2D SoftBody In Godot In 20 Minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Thank you for recording and sharing this! There are not many resources or tutorials on Godots Soft Bodies (if any), especially in 2D, so this is much appreciated! I wonder can demonstrate how to make the deformations smoother, less glitchy.

Btw, if you want to change the values of all your DampedSpringJoints all at once, you don't have write a script or select them all one by one. You could also right click and "Save Branch as scene" on the first one, and then make each DampedSpringJoint node an instance of that scene. Now you only have to change those values once.

👍︎︎ 4 👤︎︎ u/golddotasksquestions 📅︎︎ Jul 28 2021 🗫︎ replies
Captions
hey guys it's me chance again today we're going to make a tutorial for soft body physics and godot and let's get right into it now the scene right here is pretty simple it's just uh no 2d and the tile map the tile map is just a square and it has collisions and stuff that's that um i have nothing else down here except a ball spike as you can see in the upper corner that's going to be the bouncing ball we're going to make so let's go into a new scene make a 2d scene we're going to name it ball and see yep it's a ball i guess um now we're going to do a sprites nodes thing but you might be like oh you need a polygon node nope i'll show you this real quick just drag your texture into it zoom in now we want this to be a little bit bigger so let's do increase three times in scale it depends on how big you want your ball to be but this is about how big i want it and click up here where it says split click it and then convert to polygon 2d and it depends on how precise you want it to be but we're going to have it be as precise as possible so let's set these to the lowest amounts they can and then update preview that means it's going to make the polygon as close to the pixels create polygon 2d now if we go up here and click uv it's going to show us all the points in it and this is where we're going to do like the forming stuff and hook up bones and polygons and points but we don't need to do that at the moment now we're going to go into the ball node and add another child we're going to add a rigid body that's not how you spell with your body yep we're going to add one of those and we're going to name it for simplicity zero i'll show you show you that in like five seconds and we're just going to add the collision shape note to it as well and to give that collision shape a circle and there we go for that make it a little bit bigger depends on how your shape is you don't want to cover the entire thing obviously but yeah so this is basically going to be the center of our rigid body and we're going to have other urgent bodies all around the edge and they're going to be connected with spring joints so it stays the relatively same shape but can stretch and stuff so we're just going to click this button right here it's just going to make sure we can't move this without moving the user body and also we're going to click this snapping tool here smart snap to help snap stuff into place easier now it's gonna be pretty simple we just copy this and the reason we named it zero is because just gonna turn the one drag it up to the very top now you want to go where the circle bailey eclipses the ball we don't want to have it go too far or the collisions are going to look weird and we're just going to do this all around the circle now if you're using a different shape for this like a square you're going to do it obviously more in a square shape but this is just for a circle so there we go now this is where the fun part comes in we have to go through each one of these and connect them with spring joints which it's not hard at all it's just a little tedious but we can get into that right now so we're gonna just go to the top one right here add a child and we're gonna look up damp spring joint 2d right here and we're just going to line this up with the middle so go to the length over here and decrease it until it's right around where you want it and then see where it says node a node b and node a you're going to select the current rigidbody you're connecting from and node b is going to connect to the body you're connecting to so for node a i would pick 1 and for node 2 i would pick 0. and you want three of these for each larger body so just ctrl d duplicate it then press e to rotate it around and we're going to rotate it to the other one turn off turn off smart snapping for this and just decrease the length so it's lined up and then turn node 1 to keep that one the same actually and turn node 2 to node 8 and now you want to do this for the entire thing so ctrl d again rotate it now it doesn't need to be perfectly lined up so if it's off a little bit it's fine and now just click two for this and you can do this exact same thing for this one and this for every single one so it's going to take you a little bit but it's not hard it's just a little tedious so now go to node 2 add child spring rotate it to the middle again decrease the length so it lines up then assign the nodes to it and just keep on doing that so now we're going to do it again with node 1. now you might be like hey you're just going to duplicate the same connection yeah um i'm not 100 sure if you actually have to duplicate it like that but i've done it like that and that's where how i see everyone else do it so i'm going to do it for this now connect to node 1 duplicate once again and just keep doing it like this um i'm gonna fast forward it now because i'm pretty sure you get the jest of it just connect into a ring have them all connect to the middle and yeah i'll be back like two seconds okay now we have them all set up now just in a nice circle and all connected to the middle if you go to debug up here and click visible collision shapes and then we save the scene we're just going to save it as ball then just save that now if we go into our scene and drag it into the main scene boop if we click on and obviously we have to click the scene tone it's going to drop it won't um the circle won't go with it but it's going to drop now it might not look like it's staying connected but it is but to make it look more ball shaped we're going to have to tweak a couple things so now go into um your ball scene and click on all of the spring joints which depending on what type of shape you're making it might take a lot but there's a couple other ways you can optimize it like doing it in script or whatever but we're not doing that today so let me explain a couple of these variables here length is obviously the length of the spring last length is like where it starts which if it's zero it's just gonna start at length st stiffness is how much it can pull apart between like how stiff it is i guess how stretchy it can be damping is how fast it comes back together so we want to increase the stiffness let's increase it to like 35 that should be good and if we run the scene again it should retain its shape more see doesn't do as much let's actually do it for extreme example let's change it to the maximum 64. and then do it again now it should keep its shape a lot more see it keeps its shape a lot so let's just keep at 64 for now now we want to let's just decrease all these so we can see the inspector better now we want to add a skeleton node skeleton 2d node to the ball and then add a bone 2d to it as well boop so this bone is going to be bone zero we're going to have it line up with the rigid bodies so it's going to be bone 0 now we just want to duplicate it drag it let's turn let's turn smart stamping back on boop then we want to rotate it to where it looks at the middle and we just want to do this with all of them so same with two three and it's not hard it just takes a second to do so don't worry about messing up by the way if you guys have any questions at all for any of this just comment down and ask me i'll reply to you eventually i'm going on vacation very soon so won't be able to apply for a couple weeks but hey so we're just going to deal with all these have them all look at it and save it now you might see hey there's al's here well that's pretty simple to fix click on the skeleton 2d click up here it says skeleton 2d and say make last pose from bones and that takes away the analysis that kind of just sets them in place i guess now we want to go to our the sprite we made or polygon tv i guess click skeleton and we want to assign the skeleton to the skeleton we made so it signs all the bones now click on uv up here click on bones actually before i do that let's click back on points click on this create internal vertex and you just want to like slap it in the middle or where your main bone is and that's maybe perfectly precise now we have to paint the weights for the bone now unlike um unity goodell doesn't have an automatic weight generator for it so depending on how well you paint the weights it's going to change how the shape bends so better you paint them by the bends but today we're just going to like a rough outline uh i'm gonna bring the paints weight all the way to max or before we do anything i don't need the sink bones to power down click this button and it just syncs them now we just draw them out the white means it's painted basically so that's for boneseal which is in the middle now this is for bone one and we just want to pick the ones nearby so like right here and the same for bone two then for bone three again not hard at all it's just a little bit tedious i guess you could say then for bone for i think i lost count already but pretty short spawn seven right here then to bone eight just double check look over real quick make sure your bones are painted correctly you might want to paint some more than others like these ones you might want to paint more because if two bones have um weights on the same point it's going to like half it for both of them basically um if that's the best way to describe it so i'm not the best at this so just like make sure it looks good and everything which i'm pretty sure it is so now we just put press okay now if we drag the bones if we drag the bones it should drag with it so see the mesh deforms with it i mean it's really weird at the moment but let's set that back to normal now go to the ball node up here and click attach a script and now you can store the script wherever you want but i'm just going to store in the script folder and now we want to let me explain to you what i'm doing right here so naturally the bones don't stay with the rigid bodies so they won't deform with it or move at all so we have to go into script and set it up so that they will unlike unity where you can just have bones be child of rigid bodies it doesn't work so it's a little annoying but oh well so we're just going to make a physics process function right here boop and it's pretty simple depending on how many bones or inject bodies you have it might depends on how many things you have to loop through but just put a for loop i in so we have eight of them so we're gonna put nine because it counts between zero and eight and then just indent it like that now we want to just loop through them all so basically get node and now we want to get the skeletons the bone node because we want the bones global position to be equal of the gibani's global position if you know i mean so now normally we you would have to make every line of code and type it out but if we do a for loop and we're a little nifty with it we can just use a couple lines so then just add a plus then we put i as string dot global position if we did that correctly it should start it so now we just need to get node again now we just need it to be the i so i as string dot global position okay now if we run the game it should work and it does which is nice but you might see a problem as right here the edges are deforming in a weird way ah let me show you it again actually yeah let me give you like half a second guys top 10 youtube creator here here to teach you how to make a soft body so as you can see it stretches weirdly which we don't want that personally it's a pretty simple fix so all we want is for these the cons to be constantly be looking at the middle so that's pretty simple so we just do this but we do need put an if statement because so if i is not equal to 0 do this because we can't have the middle one be looking at the middle because it's already in the middle you see so now we just need git node [Music] skeleton [Music] as string right here that look at look at and now we need to get the get get node zeo dot global position so now if we do this again it should look nice now the reason it doesn't look the best at the moment is mainly because of the way we painted the nodes unlike having the program generate the nodes for us the weights for it we have to paint them manually so it's not perfectly evened out so if you make a program that will generate them for you it will make it a lot more realistic you could always just mess with it yourself but i'm not gonna go into that too much detail on this one now there's another thing we can do so if we have it run as you can see when it's sliding on the ground it doesn't like rotate at all and that's because we have the rigid bodies set into rigid mode that means that they can rotate without sticking i guess so if we change it to character it should rotate more probably not the best example right there but let me just draw a couple more things guys there we go make a stair so it like rotates now you might be like hey chance it's sticking well let's see what the problem is right here so if we run this again oh it's that although your bodies are getting caught on the corner so we can change a couple things in here to make it a little easier for instance we can change the damping or the stiffness but i don't think i'm going to do that in this video it works pretty good most of the time actually so it's a squishy ball now if we obviously change the damn uh the stiffness of it so it takes like six years to clip these you could probably have something loop through your children and change all the values that way but i'm not making that in this one so we can change the stiffness to like 40. and let's decrease the damping too so there's a 14.5 and it's probably gonna be a little squishier yep it's a little squishier than another one but the main problem with the deformed feature is the way we painted the weights as i said before that's the main problem with it but you could always try to make a program that paints them for you hey if you guys find a plug-in that paints the weights for you tell me please and i'll make an update tutorial i guess but let's turn this off with the collision shapes and show it again so i mean it's a soft body it's not the best soft body but it is a soft body i never agree that would give you guys quality content let's for the fun of it add a bunch of these in here it's probably going to mess up some of the things yeah they all look weird but yeah that's the thing you get when get those i have a built-in um soft body feature well they do but they don't oh well i'm gonna stop gibber driving and i'll see you guys again have a good day and bye now where's that off button there you are
Info
Channel: Chance. E
Views: 1,148
Rating: undefined out of 5
Keywords: godot tutorial, Godot, Engine, tutorial, softbody physics, soft body godot 2d, softbody 2d unity, game engine development, dani, miziziziz, heartbeast godot, platformer
Id: fK3oUe1XUqw
Channel Id: undefined
Length: 21min 16sec (1276 seconds)
Published: Tue Jul 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.