Search Unity

Attempting to make 2d rope physics

Discussion in 'Physics' started by rflagg, Sep 27, 2016.

  1. rflagg

    rflagg

    Joined:
    Jan 18, 2013
    Posts:
    30
    In my attempts to make 2d rope I've tried doing what a lot of people recommend, make it more like a chain of gameobjects with rigidbody and joint. I've also added colliders so that it interacts with the environment. What I dont understand is why the joints act springy. Doesn't matter if I use distance or hinge joints. If I have a distance joint connecting two bodies together at a distance of 1, why is it that that distance can be greater than 1 during any frame? Dont understand that. To make it less spring it's helped to increase the number of position iterations in the physics, but its still not perfect.
     
  2. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
  3. rflagg

    rflagg

    Joined:
    Jan 18, 2013
    Posts:
    30
    Thanks. I've actually tried hinge joints, but in my version of unity I didn't see the spring option. I wonder if that was added in a recent release? I'm going to upgrade and make sure Use Spring is disabled to see if that fixes my issue.
     
  4. rflagg

    rflagg

    Joined:
    Jan 18, 2013
    Posts:
    30
    Nevermind I was looking at the 3d hinge joint. HingeJoint2D doesn't have that option to disable the spring effect. :(
     
    DroidifyDevs likes this.
  5. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    So... use the 3D hinge joint?
     
  6. rflagg

    rflagg

    Joined:
    Jan 18, 2013
    Posts:
    30
    But my game is 2d. 3D and 2d physics don't interact with eachother I thought...
     
  7. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
  8. rflagg

    rflagg

    Joined:
    Jan 18, 2013
    Posts:
    30
    It's under the 3D physics reference section. All of the physics stuff is 3d unless specified as 2d. And the two physics engines don't interact with eachother.
     
    logicandchaos and DroidifyDevs like this.
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,473
    If you're creating a deep hierarchy of joints to form a rope/chain then I'd recommend that you additionally add a DistanceJoint2D with its MaxDistanceOnly set to true that connects the start/end of the rope/chain. This way, the structure will never exceed a certain distance (the length of the rope/chain). This stops the stretching you're seeing.

    When the MaxDistanceOnly is set to false then we use a b2DistanceJoint whereas when it's set to true we use a b2RopeJoint behind the scenes.