- Home /
Recalculate hinge connected anchor
How can I get my Unity to recalculate the connected anchor while the game is running? I can't just move hingeJoint.connectedAnchor because I have the feeling there is another easy way around.
It often helps if you back up and describe the game-view behavior you want.
This sounds like the "clip-on hinge" issue, which I solve by nulling the connectedBody, moving myself, then resetting the connectedBody, but I can't tell.
Answer by skylem · Jan 19, 2015 at 12:59 PM
by recalculate do u mean autoconfigure? u can access the auto configure property like so.
HingeJoint hj = gameObject.GetComponent<HingeJoint>();
hj.autoConfigureConnectedAnchor = true;
or do u mean the position in worldspace? because that would be dependant upon the position of the Rigidbody its connected to, if none of this helps please clarify exactly what you mean by Recalculate.
Yes. I mean the autoConfigure but in the Inspector, the connected anchor moves with anchor automatically but not while playing.
I wanted Unity to autoConfigure my connectedAnchor WHILE running.
Answer by fra3point · Jun 17, 2020 at 01:57 PM
Yes, this post is quite old, but if anyone is still looking for a solution, here it is:
joint.connectedAnchor = joint.connectedBody.transform.InverseTransformPoint(jointRigidBody.transform.position);
The OP already mentioned changing connectedAnchor. They wanted a different way. It sounds as if you're saying there is no better way.
Actually, there's no better way to do it, and the assumption that "there's an easier way to recalculate the anchor" is incorrect.
As mentioned, using "autoConfigureConnectedAnchor" doesn't update the anchor every frame while in play mode (I'm not sure whether this is intentional or a bug) so we're forced to do it manually, calculating the local position of the joint relatively to the connected body and assigning it to connectedAnchor.
For my experience, this is the only working solution.
Your answer
Follow this Question
Related Questions
How to use character controller to push down hinge joint properly 1 Answer
Catapult press spacebar to launch / throw 1 Answer
GameObject problem 1 Answer
My Fixed Joint springs back to Zero. 0 Answers