Search Unity

A question to pose against ropes

Discussion in 'Scripting' started by Saldog, Jun 13, 2013.

  1. Saldog

    Saldog

    Joined:
    Sep 12, 2012
    Posts:
    28
    Hey guys,

    I wanted to ask if anyone has a good idea on how to make a rope that behaves according to physics, It will be used in a 2D environment.

    If I understand how the rope stays linked together while looking natural I can figure the rest out myself.

    Thanks

    ~Lyl
     
  2. george-daters

    george-daters

    Joined:
    Jan 22, 2013
    Posts:
    35
    You could think about your rope as a collection of nodes where each node has a rigidbody and is connected to adjacent nodes with one of the joint components (fixed joint, spring joint). The more realistic rope has more compacted nodes. Because you are making a 2D game you could possibly freeze the dimension on the rigidbody that you don't use. You also need a mesh and collider on the rope nodes I guess. I've created a rope like this before but perhaps there is a better way
     
  3. Saldog

    Saldog

    Joined:
    Sep 12, 2012
    Posts:
    28
    Thanks for the reply, I was thinking that if I couldn't find a "proper" way to do it I would resort to a chain of rigidbodies. Bu I thought there would be a better way since when I try that it always looks twitchy and weird.
     
  4. gtzpower

    gtzpower

    Joined:
    Jan 23, 2011
    Posts:
    318
    I have actually spent a lot of time in PhysX on this particular type of task (though in another game engine), and we have done connected capsules with spherical joints before with success. Our best ropes came from using PhysX softbodies, they looked quite natural. Not sure what all unity supports in the line of cloth/softbodies though. Soft bodies did not do too well at holding weight either, so the method would really depend on what it would be used for.

    If I were to do it again in unity, assuming soft bodies are not supported (?), I'd try the jointed rigid bodies and have the bones of a skinned mesh (that represents the visual rope) parented to the rigidbodies. Adjusting the inertia tensors should help with twitching in PhysX (haven't done this much in unity though, so I'm no expert on how to do it in the engine). Long thin capsules would have 2 axes with high inertia and 1 axis with low inertia. the low inertia axis would be the axis running the length of the capsule. If its twitchy, just keep increasing the inertia and it should stabilize. Maks sure there aren't any large mass jumps in the chain either (don't go from a 5kg rope node to a 5000kg weight on the end, physX likes masses less than a 1:10 ratio). Increasing the physics frequency will also help.

    Hopefully this helps. Sorry its not more specific to Unity.
     
  5. Saldog

    Saldog

    Joined:
    Sep 12, 2012
    Posts:
    28
    Thanks alot for taking the time to write that.


    Some of the terminology is lost on me, but I get the gist of what you're saying, I will definately try this approach, It makes alot of sense and there won't be any gaps if it's stretched slightly.

    With the Physx side of it, I don't know how I would go about implementing Physx but I will try to replicate what you said using unity's inbuilt physics engine.
     
  6. Saldog

    Saldog

    Joined:
    Sep 12, 2012
    Posts:
    28
    Thanks alot for taking the time to write that.


    Some of the terminology is lost on me, but I get the gist of what you're saying, I will definately try this approach, It makes alot of sense and there won't be any gaps if it's stretched slightly.

    With the Physx side of it, I don't know how I would go about implementing Physx but I will try to replicate what you said using unity's inbuilt physics engine.