Search Unity

How can I make a moving hinge joint?

Discussion in 'Physics' started by arcoes, May 13, 2016.

  1. arcoes

    arcoes

    Joined:
    May 9, 2016
    Posts:
    4
    Object A is set to follow my mouse, object B is attached to object A with a hinge joint. I need object B to rotate around the Z axis only and also follow object A as I move my mouse around. So if I were to move the mouse, object B will sway. I want to add additional pieces to do the same. It's pretty much a moveable chain. How can I do this?

    I've been trying for a few hours now with no luck.

    Right now I have the following

    Object A:
    - Fixed joint, no connected body

    Object B:
    - Hinge joint, connected body to object A

    B seems to rotate fine however it doesn't follow because i would assume the anchor is preventing it. I've tried making B a child but instead of rotating, the model gets a skewed and I'm not really sure whats going on


    Nevermind, I figured it out finally! Not sure how to delete post though
     
    Last edited: May 13, 2016
  2. nestorcaro

    nestorcaro

    Joined:
    Dec 28, 2015
    Posts:
    4
    Hey, you might as well post your solution instead of deleting the post ;)
    I'm having the same problem here.
    Thanks :D
     
    JaiSu and riz2o like this.
  3. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    Fixed Joint on objA is unnecessary and may cause issues.

    Also, make sure you're moving objA using physics (rigidbody.velocity) and not setting the position/rotation directly.
     
  4. riz2o

    riz2o

    Joined:
    Mar 24, 2018
    Posts:
    2
    Please tell us how you solved this issue, do not delete the post!
     
    red1monster_unity likes this.
  5. Kristis

    Kristis

    Joined:
    Mar 9, 2015
    Posts:
    1
    Make rigidbody IsKinematic to true. Do this for the first link and the last link of the chain. Now you will be able to move the chain links that are kinematic and the rest of the chain will fallow it as intended. Hope this helps.
    - Kristijonas
     
  6. methusalah999

    methusalah999

    Joined:
    May 22, 2017
    Posts:
    643
    tl;dr: move (or rotate) the transform, then set the autoConfigureConnectedAnchor of the joint to false, then back to true in the same frame. This will reset the joint anchoring.

    If you try to change the position or rotation of a gameobject with a joint, or if you try to move or rotate its rigidbody, you will have to face the resistance of your joint. To move or rotate an object that is jointed with another, you must change the anchoring. Then anchoring is the position and rotation of your jointed object, relatively to the connected body.

    You can efficiently translate a jointed object, if you update its anchor position accordingly. If you translate an objet by (1, 0, 0), you just have to add (-1, 0, 0) to the anchor. You can even change the connectedBody anchor if you like.

    For the rotation, its a lot more tricky. Joints don't give access to the anchor rotation and allow only to set primary and secondary axis, which is a pain in the ass in my opinion. You can try to rotate your object and then change these two axis accordingly, but this is way more painful than it is for a simple transaltion.

    Now there is a much simpler way, consisting on reseting completly the anchoring. This solution will only work if you are using automatic anchoring for your joint. You just have to set the property "autoConfigureConnectedAnchor" to false, then back to true. Each time this value is set to true, it will calculate the anchor position (and rotation internaly, even if it's visible nowhere in the inspector) considering the actual position and rotation of the jointed object.

    So change your object position and rotation as you wish, then use this trick and you will be able to move a jointed object relatively to the connected body without facing the joint constraint. Be careful though, it may be CPU extensive, depending how the rigidbody react to this change, I don't know. It works for me.