I’ve run into an interesting issue with physics using rigidBody.freezeRotation. Using it as shown in the lecture, the ship tips over very, very slowly when no buttons are being pressed. I experimented and discovered that setting it to true only when a A or D is being pressed, it behaves naturally again. Is anyone else experiencing this?
With the code as it is in the lecture:
“Fixed” functionality:
private void Rotate()
{
float rotationThisFrame = rcsThrust * Time.deltaTime;
// Temp hack for testing. WHY DO I NEED TO DO THIS???
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
{
rigidBody.freezeRotation = true; // take manual control of rotation
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward * rotationThisFrame);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(Vector3.back * rotationThisFrame);
}
rigidBody.freezeRotation = false; // resume physics control of rotation
}