I'm trying to freeze both position.x and rotation in Rigidbody2d in a script but i cant manage to freeze both of them. any ideas?
here are the commands i use: GetComponent ().constraints = RigidbodyConstraints2D.FreezeRotation; GetComponent ().constraints = RigidbodyConstraints2D.FreezepositionX;
It only gives me the choise to freeze position x and y or the rotation only or alla of them at the same time.
I just only want to have the position.y unchecked which i can do it manually in the inspector but not in the script.
Any ideas????
Answer by MelvMay · Nov 28, 2015 at 10:59 AM
The constraints property is a Bitmask. Simply setting it to a single option only sets that option. You need to use the | (bitwise OR) operator to merge them together before setting it i.e.
constraints = RigidbodyConstraints2D.FreezeRotation | RigidbodyConstraints2D.FreezepositionX;
Your answer
Follow this Question
Related Questions
Freeze all falling objects on y-axis 0 Answers
i cant see the constrainst in rigidbody2d need help 0 Answers
Whole computer tanks while starting Unity games. 0 Answers
How freezing AR Camera when hitting an Object 0 Answers
Nothing is working in 3D 0 Answers