Hinge Joint not working in Unity 5

I just upgraded from Unity 4.5 to 5 and everything is looking good except the hinge joint in my scene is behaving differently than it used to. I was using it to simulate a spring board using a script. When the player clicked on a object and dragged it back, the script would interpolate that distance the player dragged and set the max angle of hinge joint to seem like it was being pulled down. Then when the player released, it would reset the max angle so that it would spring up.

However after upgrading, the hinge joint snaps all the way back as soon as I hit play and won’t move at all. I also notice a message in the Inspector that wasn’t there in the previous version. It says “Max Limit needs to be larger or equal to the Min Limit.” That makes sense since my Min is 45 and my Max is 0, but that is the value that made it work the way I needed it to previously so I’m confused why it won’t work now.

Here is the script I have attached to the hinge joint object:

private var minAngle : float;
private var maxAngle : float;
var tracker : Transform;
var launchPivot : Transform;

function Update()
{
	//Calculates the distance between both objects
	var dist = Vector3.Distance(tracker.position, launchPivot.position);

	//Interpolates angle of object dependant on distance of two objects
	var angle : float = Mathf.Lerp(maxAngle, minAngle, dist/5);
	
	//Changes angle of object by limiting hingeJoint max limit property
	GetComponent.<HingeJoint>().limits.max = angle;
}

Any help is appreciated. Thanks.

I’ve also encountered problems with physics joints when upgrading to Unity 5. I believe that in the new PhysX version, joints are much more picky. Try doing these two things:

  • If the rigidbodies have position or rotation constraints on any axis, make sure that only the connected bodies (the dominating ones) have those constraints. If both rigidbodies have the constraints, the joint f*cks up for some reason.
  • Try disabling the Enable preprocessing checkbox, at the bottom of the joint component in the Inspector panel.

Good luck!

Not sure if it helps you, but one thing I’ve noticed is that joints now behave differently if you don’t have colliders also attached to the game objects.