How to lock x axis while rigibody moving?

Take a look at the attached images.
While rotatating the frame box, I need the yellow cubes(Rigidbody) to fall down directly, without any change about x axis.

I’ve ever tried this, however it doesn’t work well.

	void Update () {
		thisPosition = transform.position;
		thisPosition.z = 0;
		thisPosition.x = Mathf.RoundToInt(thisPosition.x);
		transform.position = thisPosition;	
		
	}

I wonder if I could configure the physics settings to disable the rebounding of rigidbody.
Any advise?

Do you need to use rigidbodies for this at all (ie, do you actually want the physical behaviour, gravity, collisions, etc to be simulated)? You might find it easier to handle the animation yourself in the Update method.