Rudimentary ‘falling block’ game. Two sprites currently, both with position and rotation ‘frozen’ in the RigidComponent2D. Gravity scale for both objects set to 1.
Goal: Pressing a key causes the block to fall.
Method: Keypress detected in Update() call, set block’s RigidComponent2D constraints to ‘None’.
Result: Constraints are removed (confirmed by checking Inspector), but block doesn’t fall.
Notes: If done without a keypress, block falls. If done by toggling ‘freeze y’ position in Inspector, block also falls.
What am I missing?
private Rigidbody2D _rigidBody;
// Start is called before the first frame update
void Start()
{
_rigidBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.Space)) {
//_rigidBody.constraints = RigidbodyConstraints2D.FreezePositionX;
_rigidBody.constraints = RigidbodyConstraints2D.None; //this gets called, but doesn't trigger the gravity to 'apply'
}
_rigidBody.constraints = RigidbodyConstraints2D.None; //this does work though
}