UE4 How to make Rope/Chain using Bones and Physics Constraints in Unreal Engine 4 & Blender Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi I'm Andre I'm going to show you how to implement rope using bones so let's see what we have here so I've made a few setups to see how the Rope behaves as you can see we can grab it if you like it let it go it collides with the environment I've also connected two objects to it so it can as you can see it can hold the two objects same thing here and I've also done I've implemented a long rope this is ten meters and fifty segments so it it's considerable but apparently it does hold now last thing we have here a rope connected to fixed points there it's actually holding a one ton weight which is a considerable weight but as you can see it does work so before I go ahead and show you how to implement it I'm gonna say a few words about ropes in general the reason why you don't see a lot of tutorials on this subject is because the ropes are hard to calibrate so they're not hard to implement as we'll see later but they are how to calibrate because they use physics constrains to hold them together so if when the physics constraints are a lot there are a lot of constraints type in a chain they will become unstable so that's the reason and also ropes consume a lot of processing power so don't expect from this implementation that you'll be able to tie knots and something like that or have a reel of rope that your long rope will usually implement stuff like this short segments that you can use in your game and just try to work with that you will be able to connect weights to them as you can see here but we'll also have to calibrate that so let's go ahead so for the creation of the rope we actually need to go into blender and create a mesh with the bones and then we'll import it here and continue here let's go ahead let's go over the components so the underlying structure of a rope is actually broken down into segments that are that we're going to implement with bones and these bones will be skinned with a mesh so it's gonna be a continuous mesh broken down into polygons there is going to be tied to these bones now in for the collision the mesh will not work for the collision we have to use capsules like you see here each bone will have a capsule for collision and finally deep the bones between each other they will believe their movement will be limited relative to each other using physics constraints and you see here so we have four components than the entire mesh and then we have segments of bones each with their collision and they are connected using physics constraints so let's go ahead in blender and we'll create the mesh and the bones let's go ahead and make a new file here I'll activate screencast keys so you can see here what I'm doing so I'll double a and remove this so now very important in order to for the skeleton wish to import correctly we'll have to set the units the world units here so in world go two units and set this to metric and here the unit scale we'll put this to 0.01 so that means the unit is 1 centimeters long now for in order to approximate a rope will use a cylinder so shift a and add a mesh cylinder or adjust to 10 vertices should be fine radius of 2.5 centimeters and a length of 3 meters now let's save this quickly ok so I have this initial ready let's move it so it looks better but as you can see here it's not smooth I'll just go to or let's move and put this 260 so it always smooth this part ok so now if you look at if you tap into the mode and look at the mesh you see that there are faces they go from from the top to the bottom and this is not good because we wanted the mesh to flex so we need to break it down into segments so we push control air r4 there and then we tap 100 so double enter now we broker the mesh down into segments so it should be ok now we want to set the origin here it's just best to have it there so we select all these vertices with space and snap cursor to select it and then we tab into object mode and then set origin to 3d cursor right here now we have the origin here we'll put because we when we export the origin that will be taken it's going to be this one right here so the world origin not this one so we'll bring that down here so I do snap cursor to Center and then snap selection to cursor like this okay so we've done the mesh now let's do the bones so shift a and add an armature add a single bone like this so as you can see it's a tiny bone we tab into edit mode will select this upper part and then G and Z to grab it down vertically and we want it to be stuck here so we'll just select snap vertices and GZ again and control so it snaps right here now the bone is the exact length of the mesh now what we have to do is actually subdivide this so we subdivide multi like this and we'll actually subdivide it into 30 segments so that's a lot of segments okay I have this done the only thing that remains to do is take this and may parrot the mesh to it so now as you see the mesh right here will parent this to the bones and we'll use weight painted parenting so let's go into the object mode you select first the mesh then select the bone and then we hit ctrl P so this will parent the mesh to the bones and we can select here with automatic weights so what that means is that here if we go into the edit mode of the mesh or see there we have segments so we have a faces like this so this paints for each bone paints the faces that will be affected by this bone so if we go into the pose mode select the armature and go into the post mode right here and select the bone if we rotate it will see that this bone affects this part of the mesh and this part of the mesh but not further here we see that it affects because it's it it parents this one to it so forth it moves but if we take this one and rotate it you see same behavior it affects only part of the mesh so if you want this to be more pretty if I can say that then you can wait paint yourself this okay so I've done this let's select the two meshes actually we'll get into a trick more here so selected two meshes and now we have to export them into FBX so if you go here FBX take this is five now very important the settings for the export first of all check selected objects here then with holding shift armature and hold shift mesh then go into the emerges and deselect add leaves relief bones like this so that's it just export this and now we go into a real engine so let's import what we done just move this so it's easier like this so if we right click and import I will take the one with the five that we just made okay now here make sure the settings are the ones that you see here important being to check skeletal mesh here so I'll show you also while you have here for a second okay so let's import that you know this this is for the mesh it's not you can result that on your own okay so we created all the assets that we need so we go into the physics assets right here now we've seen that we need a bone a mesh a bones a mesh capsule collisions and physics constraints as you can see it already created for us on physical strength and capsule collision but it's not good because it's not for all of this let's go here and delete that we'll get rid of those like this okay so now select all control a select all here and then we go into the tools here so this is going to allow us to create capsules and physics constraints so here put any Mambo size to 10 put any weight right here just look at these settings and do the same exactly the same as you see here so if we add here the bodies I can see that it already did the job for us because Manuel is this would have been really hard to do okay so now if you look at the graph here on the Left we have on the left and on the right we have the physics bodies the capsules and in the middle we have the constraints so a capsule is cus connected with the constraints to another capsule that's what's happening here so now we can go ahead and set the capsules so if you select all these capsules from top to bottom I see they're selected here we can go ahead here and set their mass we'll put the mass of 1 kilo let's say I'll put a linear damping of 5 as you're playing 5 sorry and we'll talk about this later here I've actually made a material for the rope so put that in this is so it has less friction when interacting with the environment so it doesn't seem that slippery ok so physics type will live like this because it's by default it's simulated but if you don't have it like this you have to put it to simulate it but I'll just leave it by default okay we'll leave the city for now like this and that's it for the capsules now if we go here and we select everything down the middle like this we get all the physics constraints as you can see here so now let's set that so first we check this able collision then we'll just make sure they had all these settings if they're not particle like that you make them like that I'm not gonna enumerate all them just make sure they're like this so angular limits so then your limits will have locked angular limits will put to limited and will change only this one so this is the twist angle and in the around the z-axis we don't want it to twist that much so just put 10 here the soft constraints will disable for now and let's just put to select it and swing here and I just put a target velocity of 0 with force of 500 this means that all the rotations that are going to happen I'll slow down so this is helps us for the stability of the rope and also it adds kind of a resistance to air which looks mix the rope and broke more natural ok so that's it that's basically right now you have a rope functioning rope so if you drag this into the scene make sure you drag the finish assets from here if we play right now as you'll see it already works okay so that's it basically now I'm going to talk about the limitations so as you see sometimes it will the rope will collide and will pass through objects like here this is kind of if I may say it's kind of normal for the ropes a there is something you can do about that but usually if you put too much force on it it will pass for other objects even if use even if you use a CCD continuous collision detection so as you can see here what does if we go here into the physics and we select the physics constraint we're actually not the capsule if you check CCD the thing is it will still pass for objects and it will also add some instability to the rope so I don't advise checking this so let's let's see what happens if we take this for example the one that we just made so look at how it behaves right now and if I activate let's take this from here go here and the physics so if we take all the all the capsules like this and we actually activate CCD and I will try again as you can see it becomes really unstable so this is because there is a lot of bodies that are colliding with each other and it just doesn't work very well with a lot of physics constraints so I would advise keeping the CCD disabled okay it doesn't matter for this one it's disabled for the other ones okay so we've seen this now the more the most important thing about probes is that they're the weight of each segments segments counts a lot so this is the main point that you can the main thing that you can do for stabilizing it is controlling its weight so if you look here for this one let's go into physics right here and we'll select all the capsules so as you can see there has a mass of five kilos so he'll play this if you look here it ports as it should but if we go here and modify this and we'll take this low like something like 0.01 don't see what will happen yes so as you can see it really doesn't like it now the problem and this is this is very important for the stability of the ropes as I said the problem is they're all these segments that we have here are connected between each other using physics constraints and physics constraints use the mass of the objects to relay the force from one object to another so I've made a an example to illustrate that just have two objects they are connected and just I'll just move this which is have two objects that are connected with physics constraint here so this constraint connects this one to this one the two cubes together if I play this what you see happening here is that the the smaller cube is actually trying to stay on the surface but it's pushed down by the larger cube now if you look at the mass of the small cube we'll see that it's zero zero one and the big one is a ton one ton so this is like 10 grams and this is one ton so this is this illustrates very well how the physics constraints work so if you have too much of a difference between between the weights that are related by the physical constraints the smaller weight will actually get carried away by the the big one and when you have collision with objects if you have a small weight here it will just get pushed into other objects so exactly the behavior that you have here so this is why when you when you put here a zero zero one if we simulate this see what happens it just passes through and then it's because it's weight is really small and these objects pull on it so hard that it make it pass through the beam right here and you can also see here let's just simulate that same thing happens here we have lower so if you go here as you can see their mass is your point zero one so the movement is very erratic because the white the white object is trying to pull this one which is heavier trying to pull it up and it doesn't arrive because the forces get scaled by the mass of each segment of the rope so if you go here and modify this and put this to a five kilo let's say so you would say that try again well now it acts as you should it's stable and it works same thing happens here and I have this object so if you look at this rope it's the same thing so we'll have to increase his mass you know in order to pose resistance to this heavy object so here if I look at our weights our methods actually I've put fifteen kilos so this is of course very big for a rope because if we have like 20 segments it goes a rope will weigh something like hundred kilos which is crazy for rope but these are the compromises that we'll have to make in a game in order for the rope to be stable so this is again this is the biggest point of stability that you can make then if you if you want to obtain different behaviors if we select the physics constraints here these will actually function as normal physics constraint like you would like you've seen in other tutorials of mine when I'm doing wheel something like that so just you'll calibrate them like that one thing you will want to play or also with is the projection so the projection is the force that is applied so let's see there we have this capsule that is pulled by a force like this well projection is actually a force that activates that a certain distance or rotation from where it should be and it actually pushes this back tries to push this back so try to actually just run this try to play around with this it will also help and also good thing to stabilize a rope is to add friction actually to add damping so if you select the capsules again you see here linear damping we've put it to one for this one the higher you go with this the more stable as it will be but the Rope will move more sorry more unnatural because it will it will lag behind so if I put this to five well I'll just leave it to one but I know that the higher ago this the more drag it will have in the air we stay behind of the movement but it will be more stabilized so this is one thing where you can add damping and the other one is actually in the physical strain so if you select the physics constraints here the one that I've already added here is the target velocity of zero for the rotation so this is when when actually when the capsule rotates around the other capsule so this limits this movement so it will actually be good because it will collide less with others so we'll create less chaos so here I've also is another subject I'll see this velocity target since we put them locked well this is a special case but usually we put them locked so you don't have to use that so yeah the big the big three points that we can use to stabilize our the projection the damping here in the capsule the damping and most important the mass now last thing I want to show you is how you can do an elastic rope and I've done this here so if you play about that let's move D here each time I play it will okay so look here you see that this actually acts as an elastic this is very nice if you want to use that it's very nice if you might use it in your game so let's see how to do this so select this go here and the physics and then we select the physics constraints all of them so first of all the elasticity we've added actually it's in you'll only modify the linear limits the angular limits have little to no effect here so just use this so the elasticity actually acts when this moves apart so this is pulled three the capsule is pulled like this a will act as a force to keep it back down so for that to work will select all the physical constraints back sorry on the physics constraints like this so we'll put the linear limits to free and then we'll go down here to the linear motor and we're gonna put the position target at zero and then a strength I've put ten thousand here because the object that are pushing onto the rope there it's really heavy like it weighs a ton so one ton so yeah I've put this here and you can also use damping so this is so doesn't bus bounce too much so it's stabilized pretty quickly so this you can use if you're doing an elastic rope this you cannot also so if you look here as you can see the elasticity does work because if we go back let's let's deactivate that let's put this two locked and you'll see a big difference now look look what happens here now there is a little bit of elasticity because of the way the physical strains work but if not there isn't there isn't much actually so if you put this back to free and you physics constraint the this reactivates and let's just bring it down let's say to six thousand so as you can see it's really elastic yeah so that's nice that's how we can do it if you want of course you can also yeah if you leave it like this it will be rigid but okay let's just say that we lock this back and let's make it rigid actually so to make it rigid so make it stay straight like this you play with the angular limits so if you bring those down to let's say five but this might also destabilize it especially if there is a heavy weight pushing on it well it does work but Jupiter's to one respite is to one yeah so because there are so many segments actually the the angle between them is what we said here is the angle between each neighbors so the angle is really low so but if we had two segments or something like that it will count a lot so if you let's put this lot let's just make sure yeah so it's really yeah it's just less than two limited like this I think it's not the best case to show this in so let's play with this one so we'll take the physics constraint all of them and then let's put this to look let's try again now so see what happens so you get you get something really like yeah and it becomes a stable yeah I was expecting that because something like a hose as you can see yeah but this is because it's trying to keep it like this so it projects it every time it passes so I would say put this to limit it maybe or no just yeah put this to limited for this to zero like this or maybe one let's put this to one and then are we can let's try it out like this so it should already be better but yeah yeah so it's already stay more stable but what we can do to to make this better it's actually activated soft constraints here for the angular limits and we'll put this to let's say 1000 or 5000 even like this and we'll add a damping also sorry it's not that it's here so we try again now we should see an improvement so it is but it doesn't stick right yeah I just try to correct itself as you can see so it acts more as a hose than rope it's more rigid but I think we should put this yeah 10000 maybe and we'll put here a zero this doesn't make much of a difference I think so so let's try again yeah so as you can see there are some limitation becomes unstable when I try to do this but first if you don't move this fast if you move as slow like this if your game of slower it's okay so now the last thing I want to show you is a thing that you can do for all groups there's a thing called sub stepping so if you go into the project settings here and look for sub stepping and you activate this this will actually because the physics objects have their position calculated each frame so usually you're tied in to the frame rate that you have but this actually lets you have steps in between those frames so the number of steps up you put here is the number of steps that we'll do between each two conservative frames so this will add this will help you with the stability should help frankly I didn't see too much of the difference as you can see here it's still yeah but it's something that you can do to improve your physics but be careful this consumes quite a lot of resources so just test it see if it works and if it actually it's worth it yeah so that's it I hope this has been useful if so please like share and subscribe and I'll see you in the next video
Info
Channel: Lusiogenic
Views: 35,451
Rating: undefined out of 5
Keywords: tutorial, unreal engine, gamedev, ue4, blender, rig, bones, rope
Id: hEMcr98cDJE
Channel Id: undefined
Length: 36min 57sec (2217 seconds)
Published: Tue Jul 24 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.