Can you unfreeze a rigidbody.constraint position as you can freeze them?

Yes, a simple question from me!

I want to freeze the rigidbody’s Y position when the game is paused, as in my script:

if(GameManager.gamePaused == true) { transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionY; }

And of course, when I unpause it I naturally want to unfreeze it. Is there a simple way to do that? I’ve looked around the various tutorials and Unity’s scripting API pages, can’t find anything about it.


RigidbodyConstraints are bit masks, thus you can use + or | (bitwise OR) to set several constraints at once. To disable a single constraint, AND rigidbody.constraints with the negated mask (~):

  rigidbody.constraints &= ~RigidbodyConstraints.FreezePositionY;

But if you don’t have other constraints active, just set rigidbody.constraints to RigidbodyConstraints.None:

  rigidbody.constraints = RigidbodyConstraints.None;

Another way to do this is to simply save the constraints in Awake or Start before changing them.

var originalConstraints : RigidbodyConstraints;

function Awake()
     originalConstraints = rigidbody.constraints;

function FreezeConstraints()
     rigidbody.constraints = RigidbodyConstraints.FreezePositionY;

function UnFreezeConstraints()
     rigidbody.constraints = originalConstraints;

Hi this code is not working (rbody.constraints &= ~RigidbodyConstraints.FreezePositionY;)