- Home /
Distance Joint 2D not working as described?
From the documentation here:
http://docs.unity3d.com/Documentation/Components/class-DistanceJoint2D.html
"Note that unlike the Spring Joint 2D, the Distance Joint is rigid and does not allow the distance between the objects to vary."
However, in practice, it acts more like a string or rope, where the distance specified is a maximum, not an exact.
To replicate:
Add two Game Objects to the scene.
Give them each a Rigidbody 2D.
Set Gravity Scale to 0 on both.
Give one (or both) of them a Distance Join 2D with the other object as the target.
Run the scene and move around one of the objects (either in the inspector or through a script)
So either the documentation was wrong, this is a bug, or I'm missing something obvious.
Thoughts?
Reading carefully we can see that the joint only avoids the bodies to come closer than the distance. The joint should have another option to never let the objects go beyond that distance. I'm finding this impossible to do without scripting. I opened a feature request, please vote: http://feedback.unity3d.com/suggestions/distancejoint2d-should-have-an-option-to-keep-max-distance
Answer by CinnoMan · Feb 17, 2014 at 11:12 AM
I've run into the same discrepancy between the description and actual behaviour of DistanceJoint2D. It's behaving like what I'd expect from the slider joint.
My current workaround: use SpringJoint2D, set Frequency to 0. this keeps the joint objects at a fixed distance without any elasticity of the link.
Nice, works like I would want it too.
I'll mark this answer as correct, though I would like to see the documentation updated.
Thanks.
PS: Can anyone see a possible down side or side effect of this work around? I can' think of any.
just guessing, but since it means using an unnecessarily complex solution it might impact performance a little.
Answer by Jellezilla · Jan 28, 2014 at 01:37 AM
Yes, I think its the description you understand differently. with good reason imo.
look at the other one: "The Spring Joint 2D component allows two Sprite objects controlled by rigidbody physics to be attached together as if by a spring. The spring will apply a force along its axis between the two objects, attempting to keep them a certain distance apart."
http://docs.unity3d.com/Documentation/Components/class-SpringJoint2D.html
The keyword there is "attempting". It allows some flex.
Distance Joint 2D is, as I understanding it, a Spring Joint 2D without that flex. But it's not. So is the documentation wrong, or the implementation?
Answer by Warped · Oct 16, 2017 at 01:54 PM
Its still not working! If you trying to move main parent object distance become increase
Answer by shivam301296 · Feb 12, 2018 at 12:35 PM
In new version of Unity they added option of Auto Configure Distance. that is the reason Just Disable Auto Configure Distance in Spring Joint 2D component and its DONE
,Just Disable Auto Configure Distance in Spring joint 2D and its DONE
Your answer
Follow this Question
Related Questions
programmatically added SliderJoint2D not respected 0 Answers
2D Grappling Hook problems 0 Answers
HingeJoint2D.GetReactionForce not working 1 Answer
keeping constant "Distance Joint 2d" 2 Answers