- Home /
 
JS - How do I change the constraints of an object?
I'd like to know how to change the constraints of a gameobject's rigidbody, in JavaScript.
For example when something of the "Sharp" tag hits this object, I want another object's Y position constraint to be turned off so that it can fall freely after the hit.
 public var lug : GameObject;
 
 function OnTriggerEnter (other : Collider) {
 
     if(other.tag == "Sharp"){
         lug.rigidbody.Constraints.FreezePositionY;
         Destroy(gameObject);
     }
 }
 
              Answer by Cherno · Mar 13, 2015 at 06:16 PM
From taking a look at the Rigidbody Scripting API, wouldn't this work?:
 lug.rigidbody.Constraints.FreezePositionY = false;
 
              When I attempt that I get the error:
BCE0117: Field 'UnityEngine.RigidbodyConstraints.FreezePositionY' is read only.
EDIT: I changed it to a lowercase and got this result.
Turns out the syntax is a bit more complicated due to bitwise operators:
Can you unfreeze a rigidbody.constraint position as you can freeze them?
 rigidbody.constraints &= ~RigidbodyConstraints.FreezePositionY;
 
                 Your answer
 
             Follow this Question
Related Questions
RigidbobyConstraints2D is not working in Unity 5.0.2f1 Personal Edition!! 0 Answers
Disabling rigidbody constraints in code - Freeze Position, Rotation etc 7 Answers
How do I query the RigidbodyConstraints? 3 Answers
Attempt to disable constraints using RigidbodyConstraints.None has no effect 0 Answers
Can you unfreeze a rigidbody.constraint position as you can freeze them? 2 Answers