Search Unity

2D joints attached to a moving object?

Discussion in '2D' started by kbobob, Jul 28, 2014.

  1. kbobob

    kbobob

    Joined:
    Jul 27, 2014
    Posts:
    2
    I am trying to attach a stationary object (a 2d ragdoll connected by hinge joints) to a moving object (a car) using a DistanceJoint2D.

    I want the ragdoll to attach to the car and go flying along with it, but the ragdoll lags behind and the distance joint has little to no effect.

    After tampering with the Physics2DSettings and changing the position iterations to something crazy like 100-150 I can achieve the desired effect, but that seems pretty ridiculous. Does anyone have an idea how I can go about solving this without cranking up the settings, and is 100 reasonable?
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I was sort of having this issue yesterday with a distance joint seeming to not work at all, and I found it was because I set the mass of one of the objects to be almost nothing... when I restored the mass to 1 it worked instantly. So I think in the physics calculations for distances/springs you need to have enough mass in order to change how much `influence` each side of the joint gives to the overall positioning, and it sort of needs to be balanced to make it a `two-way` influence ie both objects pull each other toward each other.... not sure if this is the case for you, but try changing the mass of the ragdoll.
     
  3. kbobob

    kbobob

    Joined:
    Jul 27, 2014
    Posts:
    2
    Hey Imaginaryhuman thanks for the reply,
    Yea, I noticed this issue with the mass the other day when I was creating a rope for my ragdoll to swing on. The rope would act all springy and the joints would separate if the mass was set too low. Unfortunately, this does not seem to be the case for my current problem and it behaves in a similar way regardless of the masses.

    Something weird, I decided to test the velocity of the rigidbody2d's on my ragdoll when it is attached to a car moving at (20, 0) and behaving properly. I expected the rigidbodies to have a velocity of ~(20, 0) as well but they all had a velocity of about (5 , -2). So I decided to have the ragdoll release the car and sure enough he had 0 momentum and stopped instantaneously.

    I have a feeling joints are not meant to be used this way, but there has to be some way to accomplish this.
     
    Last edited: Jul 29, 2014