I recently needed to implement rope swinging in a project I'm working on and wanted to share how I did it (since there isn't very much talk on this topic). I'm creating a swing with the Unity Component HingeJoint creating it via code (instead of in the Editor) when the user left-clicks then destroying it when the player releases the button. I'm creating and destroying the Component because I only want the player to be attached when holding down the button and HingeJoints can not be disabled. I'm using a Player and Anchor GameObject. The Anchor isn't rendered but is moved to the point where you're swinging from on click. The Anchor NEEDS a HingeJoint too! If only the player has a HingeJoint it will create unexpected behaviors. Code (csharp): /** On left Click **/ //move the anchor to the correct position anchor.transform.position = new Vector3 (hit.point.x, hit.point.y, 0); //zero out any rotation anchor.transform.rotation = Quaternion.identity; //Create HingeJoints joint = gameObject.AddComponent<HingeJoint> (); joint.axis = Vector3.back; /// (0,0,-1) joint.anchor = Vector3.zero; joint.connectedBody = anchor.rigidbody; anchorJoint = anchor.AddComponent<HingeJoint> (); anchorJoint.axis = Vector3.back; /// (0,0,-1) anchorJoint.anchor = Vector3.zero; //Now just add Force! /** On left Click release **/ //Destroy HingeJoints Destroy (joint); Destroy (anchorJoint); Notes Player input for movement adds force to the Player's Rigidbody in the left and right direction I'm using a LineRenderer and a double faced material (no culling) to draw the line Make sure there aren't any colliders on the Anchor or physics will affect it creating unexpected behavior I have constrains on the Player's Rigidbody because I'm working on 2D and don't care about an axis I hope this is helpful, happy Coding!
Thanks for sharing. I started work on a ninja roping game last year which unfortunately i've been too busy to complete. I have all the rope wrapping and unwrapping working nicely, and left it halfway through the physics stage. From memory I believe I went for the same joints you did and it was working ok, but not perfectly, so when I get the chance to continue working on it, i'll refer back to this post for guidance.
Thanks for sharing your work! However i'm getting a parsing error, is this becuase i'm working in 3d and not 2d?
Sorry for necro, but does anyone have any idea have the force should be used? Should I use rb.AddForce() or something else? I'm doing this in 3D by the way.