- Home /
Configurable Joint 2D Equivalent?
I'm doing a game with similar mechanics to "Cut the Rope" - I actually have a system that works quite well - I use a Configurable Joint on each Rope Anchor, and connect it to a "Player Object", and set its linear limit to the length of the rope. I then use a Verlet method to generate a rope mesh which sags etc (but the physics are all controlled by the Config Joint).
However, it's a 2D game, using the 3D physics (rigidbodies etc) with axis restrictions- and 4.3 dropped, I'm trying to convert my system over, so I can use 2d collides etc, and make things more efficient.
I'm running into an issue with my rope system in that I'm not sure how to replace the configurable joint I use with a 2D equivalent.
My first thought was to use a Slider Joint 2D, to handle the variable length, but that didn't produce good results.
I then tried to use it in conjunction with a Hinge Joint 2D (with the hinge as the parent), which worked a bit better, and I could get a pendulum motion going, but would still have issues when the "Player Object" would fall from above, with the Hinge Joint at some angle - the Slider Joint wouldn't seem to contract, but instead the force would make the Hinge Joint rotate faster - which kind of makes physical sense if I think of a Slider which can only slide on one axis.
The Configurable Joint actually has its angular motion locked, and just moves along X and Y (I don't completely understand this...but it works).
Is there a 2D Joint or some combination that would allow movement along X and Y similar to a config joint, or some other method I could use to make this work?
Here is my code to initialize the Config Joint:
//Adding a configurable joint to the rope anchor
cj = anchorObject.AddComponent<ConfigurableJoint>();
cj.anchor = Vector3.zero;
cj.axis = Vector3.zero;
cj.autoConfigureConnectedAnchor = false;
cj.connectedAnchor = Vector3.zero;
cj.secondaryAxis = Vector3.zero;
cj.linearLimit = new SoftJointLimit() { limit = targetLength, bounciness = 0, damper = 0, spring = 0 };
//We want to limit motion along the X and Y axis, to a maximum distance of "targetLength", and of course lock motion on the Z axis
cj.xMotion = ConfigurableJointMotion.Limited;
cj.yMotion = ConfigurableJointMotion.Limited;
cj.zMotion = ConfigurableJointMotion.Locked;
//The configurable joint doesn't need to rotate, but makes no difference if it's set to Locked or Free (don't really understand why at the moment)
cj.angularXMotion = ConfigurableJointMotion.Locked;
cj.angularYMotion = ConfigurableJointMotion.Locked;
cj.angularZMotion = ConfigurableJointMotion.Locked;
//Attach the configurable joint to the player's rigidbody
cj.connectedBody = connectedObject.rigidbody;
http://www.box2d.org/manual.html#_Toc258082974 - seems like a Box2D RopeJoint (8.13) would do the trick, but that didn't seem to get brought in?
Your answer
Follow this Question
Related Questions
What are the main differences between Unity Physics engine vs Box2d physics engine 0 Answers
Converting character to configurable joints 0 Answers
Box2D empty gameObjects not getting expected results code is included 0 Answers
Slide then lock slide when object is rotated past a certain angle. 0 Answers
If a joint has a Connected Body, does it ignore the Anchor position? 1 Answer