Unity Distance Joint2D seemingly breaking for no reason

25 Views Asked by At

So I am trying to simulate a scale (See image). The way I do it is by having three game object: One for each side of the scale and one for the horizontal bar connecting them (The support does not exist as far as physics care). The bar has Rigidbody2d with only rotation allowed + a collider and the hands of the scale have colliders and rigidbody with only y movement allowed + distance joints to the sides of the bar. I made sure to set them EXACTLY the same.

When I put a weight on the left side it works great, scale goes down, then I remove it, balanced again, when I put one on the right though the joint breaks.enter image description hereSettings for Rigid2d and distanceJoint2d on the right hand of the scale [Scale (for illustration)]

I would almost believe this is a problem on Unity's end but I would like to be sure, and obvioulsy to know what I am doing wrong in the case I am

Thanks in advance

1

There are 1 best solutions below

2
CoderMuffin On

I was able to get this working using the following configuration:

Note the use of hinge joints as opposed to distance joints. The full configurations are below, but the basic idea is as follows

  • For the scale plates, attach them to the scale bar using a hinge joint
    • Lock the Z rotation, but do not lock the X/Y position
  • For the scale bar, attach it with a hinge joint to a static rigidbody (called ScaleAnchor here)
    • Lock the X/Y position but not the Z rotation
    • Also ensure that it is dynamic, not static

Hierarchy Scene

The ScalePlates are configured like so:

ScalePlate

And here is the ScaleBar

ScaleBar

ScaleAnchor

ScaleAnchor