How can I make a moving hinge joint?

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

Hey, you might as well post your solution instead of deleting the post :wink:
I’m having the same problem here.
Thanks :smile:

2 Likes

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.

2 Likes

Please tell us how you solved this issue, do not delete the post!

1 Like

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

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.

5 Likes