unity rigidbody freeze position script code example
Example 1: freeze axis in script
public Rigidbody2D rb;
void Start()
{
rb.constraints = RigidbodyConstraints2D.FreezeRotationX;
rb.constraints = RigidbodyConstraints2D.FreezeRotationY;
rb.constraints = RigidbodyConstraints2D.FreezeRotationZ;
rb.constraints = RigidbodyConstraints2D.FreezePositionX;
rb.constraints = RigidbodyConstraints2D.FreezePositionY;
rb.constraints = RigidbodyConstraints2D.FreezePositionZ;
rb.constraints = RigidbodyConstraints2D.FreezeAll;
rb.constraints = RigidbodyConstraints2D.None;
}
Example 2: rigidbody2d freeze position
public Rigidbody2D rb;
void Start()
{
rb.constraints = RigidbodyConstraints2D.FreezeAll;
}
Example 3: freeze position unity c#
rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ;
Example 4: rigidbody freeze position through code
rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
Example 5: how to freeze an object's position unity
rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;