- Home /
How do you make ropes?
Hi, guys! So how do you make ropes? As far as I understand there is no "rope object" in Unity. I want to do the following: To make a crane with a rope, one end of the rope is attached to a cylinder and when the cylinder rotates it winds the rope onto itself making the hook go up, when it rotetes in the opposite direction it unwinds the rope making the hook go down. The derrick of the crane is also able to go up and down. On the end of the derrick there is anothe cylinder that is also interacts with the rope. I think I post a picture to visualize my words.-) I apologise for the quality of the picture, I'm not that good at Photoshop.So how do you make something like this:
Any suggestions?
P.S. I looked up this topic:
http://answers.unity3d.com/questions/2217/tie-objects-togethe
and the scripts are greate, but the rope doesn't interact with rigid bodies. Also I tried to use a skinned cylinder, but it also doesn't interact with rigid bodies.
Deleted answer by Jake 2 due to reports of links gone bad and now containing viruses due to domain shifting.
Answer by equalsequals · Jul 16, 2010 at 03:11 PM
If you want to make a physics rope, it will take several segments of rigid bodies attached by Joints. Currently your best bet would be the HingeJoint.
I recently worked on a Unity-powered game where we had a chain/rope-like string of objects that trailed behind the character and that was the class we used to tie those rigid bodies together.
I'm going to be honest, this is a pretty intricate task and there isn't really an easy way to implement this - especially the winding/unwinding functionality.
My personal advice is this - fake it as best you can. Unless the entire game is solely about the most realistic crane ever built, just fake it.
Judging by the bottom-left image (stick man "platforming" on the crane) Correct me if I am wrong, but I'm guessing that you are making a platformer of sorts.
When it comes to production you want to look at a cost-per-component ratio. You want the most important features, like your controls and other main game mechanics to have the most time/money invested. If something is rather minute in scope, insignificant in the grand scheme of things, investing so much time as to create absolute real-world physics is going to blow the cost/value of component ratio way out of proportion.
It's really up to you to decide how important any component of the game is, but a rule of thumb I use is how often any one component appears in the game. If you've got 1-2 cranes in a level - not so important. Again, if the crane is the entire game, essentially, disregard what I said, use the HingeJoint class, and I will eat my hat.
In the scenario where it should just be faked, I would do it using animations and coordinated/synced interpolated collision geometry to achieve a "good enough" product.
Sorry for the length, hope this helps.
==
Thanks, equalsequals! I'll try the hinge joint thing. I want rope to be as realistic as possible. Because the level consists of a platform and two cranes, so the cranes(and ropes) are important.
But the top two green "wheels" + the rope between them, can be faked without ruining the actual game as I see it. Just make the "hinge joint" from the tip of the crane and down. Dont make the "roll around barrel" part with real simulation, just fake the look with animation or place the "wheel" inside a box so you can only see it going in through a hole.
Answer by paste120 · Jul 16, 2010 at 06:24 PM
Physics rope could be created in Unity3 by using the new cloth system. Demo video: http://blogs.unity3d.com/2010/07/13/unity-3-feature-preview--cloth-physics/
Wow! Very cool feature! But unfortunatly there is not unity3 yet, only beta for the ones who pre-ordered the product. I use indie version.
Ya, I'm sorry. I've upgraded and have access to the beta. It's well worth the upgrade. You would be able to accomplish your idea much easier in 3 with a physics cloth cylinder, but with 2.6 equalsequals is right.
Answer by buestad · Nov 29, 2012 at 02:45 PM
PhysX (the buildt in physics engine) is useless for creating ropes/chains using RigidBodys and ConfigurableJoints if you are attaching anything "heavy" to the end. The reason is that PhysX only has an itherative solver. You need a direct solver for this.
I've done some testing using OpenDynamcsEngine and the direct solver (use the world.step() function, not the world.quickStep() which uses the itherative solver). ODE is originally written in C/C++ but there is a port to Java called ODE4j which quickly can be compiled to a C# .dll using IKVM
My tests so far is really promising!
The attaced image shows my setup: The load of the ball is 10 000kg, and the steel rope is 47mm thick whith a densyty of 7000kg/m2 which is close to iron. The crane parts are 3 000kg for the main jib and the king(the cylinder thing) and 2 000kg for the knuckle jib. Both jibs are attached using limitless ODE hinge joints and the hydraulic cylinders which hold everyting up are limited ODE PRJoints (whiche is like a slider and a hinge put together)
it's admirable you did work with ODE http://www.ode.org in Unity.
it's an interesting observation that the usual ropes everyone uses in PhysX (just get any of the "ropes" kits from the asset store) are not suitable for a weight on the end.
@buestad How did you integrate ODE exactly? It's not working how I tried it :/ Can you help me?
@LucaH007 It's a wile back but I'll try to remember....
I made this at work so I have a layer on top of ODE4j so my implementation is probably a bit different than a clean ODE4j implementation. But it shoud be possible without this layer.
First you need to make a .dll of ODE4j using I$$anonymous$$V$$anonymous$$. Download the latest I$$anonymous$$V$$anonymous$$ and ODE4j. I$$anonymous$$V$$anonymous$$ expects one or more .jar-files, so if you download the source code of ODE4j I guess you will have to ANT it...
When you have your C# ode4j.dll put it inside the Assets folder together with the I$$anonymous$$V$$anonymous$$ .dlls
Then you have to start to make a bunch of C# scripts to put on different GameObjects in Unity. The diffetent C# scripts should contain the ODE objects. Start implementing World and Body. Remember that the instance of World has to be created before you can create instances of Body, so you need to implement some kind of system that makses sure that the instance of World is created first, or a callback when it is created. You don't have control over which C# script of which GameObject is started first...
By the way, when using I$$anonymous$$V$$anonymous$$ you have to set the the API compatibility level to .NET 2.0 (not subset)
@buestad First of all, thanks a lot for your answer! I stuck right in the beginning at converting ODE4j to a jar and then to a dll file... I got an ode4j.dll file but I can't call it in Unity by script... (For your information: I'm beginner ;) )
But I found out that you can use the original ODE library in Unity somehow. (http://docs.unity3d.com/$$anonymous$$anual/NativePlugins.html)
Now I don't know how to go on xD
@LucaH007 if you use the original ODE written in c++ you'll have to add some information so that the C# code knows where to find the functions inside dll. I am no expert in c++, C# or dlls in general (by far), so therfore I went through I$$anonymous$$V$$anonymous$$ which generates C# spesific dlls.
I made a jar of a version of ODE4j which was on my drive. I think it is ode4j 0.12.0-j1.4, and compiled a dll with ikvm-8.1.5717.0. Then I included the dll, together with all dlls of I$$anonymous$$V$$anonymous$$ (the x86 versions) and made a simple test project in Unity 5.2.2 x86.
I will P$$anonymous$$ a zip of it to you if I can figure out how :)
@buestad That would be great! Unity ropes leave me desperate :D
I think there is no way to P$$anonymous$$ via unity forum/answers so just send me the zip to this temporary email: LucaH007@cuvox.de :)
Answer by King_Kurl · Aug 27, 2016 at 06:54 AM
Not sure if you already got what you needed but I remember some time ago I was looking for the same thing and stumbled on this script which pretty much turns a line renderer into a rope. I don't remember how well it worked but in case you want to give it a try here's the link.
This works, but unfortunately still suffers from the same issues that all ropes made using PhysX seem to suffer from: the joints can stretch too much and go unstable is you have a mass ratio of more than ~1:10 for what's on the end of the rope. Things get better dramatically when position and velocity iteration count are increased to ~50, however this leads to big performance issues. Good find though! and certainly a solution if you don't need big forces in the rope
UPVOTE !! for most people this answer still is the best answer. they type "make rope unity" in google and arrive here because the title states "how do you make ropes?". and this script is a perfect answer for this question. this script works perfectly even with unity 5.4
This is helpful, but was confusing to get working at first (I didn't have objects far enough apart).
Add this to get a menu item that adds an example to your scene. Then hit play, open Scene panel, and grab "start", and wiggle it!
using UnityEditor;
// ...
[$$anonymous$$enuItem("Tools/Setup Rope Example")]
static void CreateExample()
{
var end = new GameObject("end");
var rb = end.AddComponent<Rigidbody>();
rb.constraints = RigidbodyConstraints.FreezeRotationX
| RigidbodyConstraints.FreezeRotationY
| RigidbodyConstraints.FreezeRotationZ;
end.transform.position = Vector3.forward * 10.0f;
var start = new GameObject("start");
rb = start.AddComponent<Rigidbody>();
rb.constraints = RigidbodyConstraints.FreezeAll; // no movement so everything dangles off of it
var rope = start.AddComponent<RopeScript>();
rope.target = end.transform;
}
Answer by daneyuleb · Feb 25, 2018 at 02:16 PM
Has anyone got the c# version of this to work?
Seems broken.
I drop the script in, attach my target object, and the rope part seems to work--a segmented rope attaches between the anchor object and the target--but... the target object deforms as it moves, squeezing and stretching all over the place.
Your answer
Follow this Question
Related Questions
2D swinging physics. 0 Answers
Hinge Joint? Unconstrained. 1 Answer
Rope Mechanics for Grapple; Climbing and Swinging 2 Answers
Creating a rope using skinned mesh renderer 1 Answer
Distribute distances between configurable joint links 0 Answers