[Question] Rocket's X and Y rotation is locked, but it can still fall over

Is there a way to fix the problem shown in this lecture around 9:40? I’ve been having the same problem where if my rocket hits the side of an object while it’s rotating, that it’ll get moved and then fall over on its face or something. Does this problem get fixed later on?

BTW, it did get it to print “dead” when it hits the ground and other obstacles.

1 Like

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 :grinning:

As for whether this gets corrected later in the course, I don’t know because I’m not that far yet myself.

2 Likes

There was also a problem in the adding tags episode, as the constraints disappeared when the mass was changed, together with the drag setting. It seems Unity have fixed this action in later releases and changing the mass does not lose other rigidbody settings.
Setting the constraints as @parmus did is a good option.

Privacy & Terms