- Home /
Other
How do I create a chain connecting two objects?
I tried using different joints but it makes my objects go flying. I want tug of war like physics. Eg. A rope connecting two objects but instead of rope i want it to be a chain. I am new to game development :P.
does it need it to use physics? i mean, if you don't have to use physics just creating a line renderer and adjusting its points from code is enough sometimes. I usually avoid rope physics because they are heavy on CPU. also there are very good assets too if want to check asset store. i recommend obi rope for rope physics.
yeah you are right I don't need physics. Can I use a quad, apply a material and then use any joints? I will check out line renderer too.
let me few $$anonymous$$utes for creating a line renderer script i will post here when i done
You can try our Obi Rope asset. It is way better than the official Unity rope. Have a look!. :-) http://obi.virtualmethodstudio.com/
Answer by SergeiKu · Dec 27, 2017 at 10:07 AM
If you want create object like rope try to use Hingle Joint component. https://docs.unity3d.com/ru/530/Manual/class-HingeJoint.html or https://docs.unity3d.com/ru/530/Manual/class-HingeJoint2D.html
Answer by NorthStar79 · Dec 27, 2017 at 11:10 AM
Hey, here a simple project that shows usage of line renderer.
you can modfy the code , add more points and simulate fake physics visuals too.
please note that, rope texture is marked as repeat at import setting, and texture mode of line renderer is marked as tile. adding more points don't simulate fake physics alone you need to modify that points positions in your code. and use this as just an example. i did create this project just in 5 $$anonymous$$utes for you, so, there may be bugs, and performance errors. its not a complete rope system nor best practice example.
This is just like i need it to be but with a fixed length. Can you help with that? and yeah thanks a ton for this!!
just move your handlers (the cubes in this expamle) with fixed distance between them. don't relly on physics (especially rope physics) because it will use much more CPU for nothing.
let me explain what i mean. lets say that Cube1 pulls the chain and drag cube2 with it. in this case you can move your cube one like this : // this is Cube$$anonymous$$ovement.cs attach this both cubes and uncheck interactable at one of them
bool interactable = true;
// void Update()
{
if(Input.GetAxis("Horizontal") != 0 && interactable)
{
$$anonymous$$oveCubes(Input.GetAxis("Horizontal"));
}
}
void $$anonymous$$oveCubes(Float Speed)
{
gameObject.transform.Translate(new Vector3(0,0,Speed)*Time.deltaTime);
otherGameObject.GetComponent<Cube$$anonymous$$ovement>().$$anonymous$$oveCubes(Speed);
}
please note that i did not test this code yet.
Answer by BOB_KSE · Dec 27, 2017 at 08:53 AM
I guess you want to create a linked list of elements.
Linked list is a dataStructure which consists of several nodes. These Nodes hold some data and also contain the address(location in ram) of the previous node.
google Linked List for more.
To know implement linked list in unity. click on This tutorial link.
& this fourm page also.
no no....i meant a metal chain ( like a rope ) connecting two objects. Let me edit my question
in that case what @NorthStar79 suggested would be best.
even though you can implement some kind of rope physics using the linked list. where each node is a small unit of a chain or something & its position and physics are governed by the node behind it, but that would overcomplicate things.