- Home /
Player freezes upon attaching a "connected body" to a hinge/distance joint
I have a game object with the following joints attached, both disabled initially.
My goal is to enable these joints via a script. When a button is pressed down, a "connected body" is attached and the joints are enabled. It will also draw a line to the position of the target object, to represent swinging. My code for enabling the joints is this:
lineRenderer.SetPosition(1, Game.toVector2(Game.toVector2(swingableCheck.objects[0].transform.position) - Game.toVector2(transform.position)));
lineRenderer.enabled = true;
swinging = true;
hingeJoint.connectedBody = swingableCheck.objects[0].GetComponent<Rigidbody2D>();
distanceJoint.distance = Vector2.Distance(transform.position, swingableCheck.objects[0].transform.position);
distanceJoint.connectedBody = swingableCheck.objects[0].GetComponent<Rigidbody2D>();
hingeJoint.enabled = true;
distanceJoint.enabled = true;
And my code for disabling it is this:
lineRenderer.enabled = false;
swinging = false;
hingeJoint.enabled = false;
distanceJoint.enabled = false;
The problem is that when I enable the joints, the player is completely unable to move until I disable them again. I have tried enabling one at a time instead of both at once, but I got the same result no matter which ones I used. What's wrong?
Your answer
Follow this Question
Related Questions
Joints 2D, rope 0 Answers
is it possible to join objects along two points? 0 Answers
How to stop an object of going to far 2 Answers
2D rope (hinge and distance) on only ONE axis 0 Answers
2D one distance at a time movement 2 Answers