- Home /
Question by
mauri11 · Aug 06, 2015 at 09:01 PM ·
rigidbody2dconstraints
RigidbodyConstraints2D overwrites previous RigidbodyConstraints2D
Why is it that in Rigidbody2D, RigidbodyConstraints2D overwrites previous RigidbodyConstraints2D. Im trying to lock Constraints on freeze postion y and freeze rotation z with code.
t.GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezeRotation;
t.GetComponent<Rigidbody2D> ().constraints = RigidbodyConstraints2D.FreezePositionY;
Comment
Answer by Positive7 · Aug 06, 2015 at 09:03 PM
By default this is set to RigidbodyConstraints.None, allowing rotation and movement along all axes. In some cases, you may want to constrain a Rigidbody to only move or rotate along some axes, for example when developing 2D games. You can use the bitwise OR operator to combine multiple constraints.
http://docs.unity3d.com/ScriptReference/Rigidbody-constraints.html
GetComponent<Rigidbody2D> ().constraints =
RigidbodyConstraints2D.FreezeRotation |
RigidbodyConstraints2D.FreezePositionY;
Yup, soon i was able to figure out that the Freeze Rotation and Positions use Enums and the bitwise OR operator was a good solution for this. Thank you