Help understanding what this is doing?

So, I really just need help understanding how this bit of the rocket ship script is working? Specifically the freezeRotation modifier.

The way I see it, the Update method calls Rotate every frame. So, the boolean is being set as true and false many, many times per second. How does this make it so that my collisions are more controllable and rotation is more manageable as demonstrated in this lecture? I just cant seem to grasp why altering between true and false would have any useful impact on the game.

code is below.

 private void Rotate()
    {
        rigidBody.freezeRotation = true; // take manual control of rotation

        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(Vector3.forward);
        }
        else if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(-Vector3.forward);
        }

        rigidBody.freezeRotation = false; // resume physics control
    }

Hi @Ian95,

The reason why you do not grasp this code is that this code does not make any sense. :wink:

Ben had an idea but it does not work as he thought it would. He removes the freezeRotation part in lecture “Spit & Polish” (currently #72) and replaces it with an actual solution.

1 Like

Well that is good to know, thanks for clarifying that!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms