Constrain Rigidbody Y Axis Rotation in World Space

I want to clamp the Y rotation of a rigidbodys physics in World Space to then be able to set it in code. This would leave the physics on x and z.

Thanks
Dan

If you want to have the ability to manipulate it in code, then do something like this:

public float RbodyAxisY = 0f;

void FixedUpdate() {
	Vector3 newRot = Rbody.rotation.eulerAngles;
	newRot.y = rbody_y_axis;
	Rbody.rotation = Quaternion.EulerAngles(newRot);
}

and change the value of RbodyAxisY whenever you want in your script.

I know this is a four year old thread, but I’m looking to do the exact same thing and I was wondering if there was a fix for the object flipping out?