I think this happens because setting RigidBody.freezeRotation
actually sets the constraints. So when we do rigidbody.freezeRotation = false;
in the end, we actually remove the constraints on X and Y we had set on the rocket. You can verify this by adding Debug.Log(rigidbody.constraints);
before and after setting freezeRotation
, e.g.
Debug.Log("Before: " + rigidbody.constraints);
rigidbody.freezeRotation = true;
Debug.Log("During: " + rigidbody.constraints);
// ... Your rotation code here ...
rigidbody.freezeRotation = false;
Debug.Log("After: " + rigidbody.constraints);
My solution is to simply set RigidBody.constraints
directly instead of indirectly through RigidBody.freezeRotation
. The Unity document is lacking a bit on this, but basically doing
RigidBody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationY;
is the same a ticking off the boxes for constraining the Z position and the Y rotation. This should be enough to get you on track
As for whether this gets corrected later in the course, I don’t know because I’m not that far yet myself.