Is it not possible to "unfreeze" a single direction using RigidbodyConstraints ?

Using:

Example, here i have ALL constraints on, and now i want to unfreeze the RotationZ
So i have to do this…

Hub.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None; // unlock all
Hub.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX; // lock X
Hub.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationY; // lock Y
Hub.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePosition; // lock pos ALL

Surely there must be a single Unfreeze options?

Check out the docs:

The constraints are a bitfield. I quote:

“You can use the bitwise OR operator to combine multiple constraints.”

This means bitwise AND (with a bitwise NOT) can undo one bit at a time.

// turn off FreezeRotationZ
rb.constraints &= ~RigidbodyConstraints.FreezeRotationZ;
5 Likes

Note that @Kurt-Dekker 's example shows that your existing way of freezing X and Y rotation and the position is incorrect. You need to do a bitwise OR to additively freeze those separate components of the Rigidbody’s motion, as in the example.

4 Likes