Search Unity

Rope-like structure, made from several connected objects

Discussion in 'Physics' started by Komposten, Feb 17, 2019.

  1. Komposten

    Komposten

    Joined:
    Jan 16, 2018
    Posts:
    1
    Hi!

    I want to make a line of several connected objects, similar to how one might make a simple rope. The actual thing I'm trying to create is a snake-like line of segments, which follow the "head" when it moves (from user input), and is physics-enabled so stuff can knock it around.
    Each pair of objects should act as if they were connected by a string:
    1) Pulling on one pulls the other along when it reaches a certain distance ("the string is taut").
    2) They should both be able to move and rotate fairly freely while the anchors are within the max distance.

    I have tried to use SpringJoint, but I couldn't find a way to configure it to have a hard max distance. I either had to set an enormous spring value (so exceeding the max distance had it pulled back immediately) or 0 friction and mass scale (so a weaker spring could keep the objects together).
    The first approach led to a big messy chaos when a sequence of objects were connected, with objects lagging all over the place. The second approach worked somewhat well, but 0 friction isn't exactly desirable.

    I also tried to put a cylinder shapes between the objects, with a HingeJoint on either side (one set to the x-axis, the other to the y-axis). I expected hinge joints to hold the anchors close each other, but that didn't happen. Moving one object forward just moved it away from the others, without pulling them along. Tried to modify the spring values, but that took me back to the SpringJoint situation.

    Am I just setting these joints up incorrectly, or are there other components/ways to do this that I have overlooked?

    (I'm quite new to Unity, so I've probably missed something obvious...)