I don't quite understand pitch


    void ProcessRotation()
    {
        // x,y,z = pitch, yaw, and roll
        // when we go up/down the y axis, we rotate by the x-axis
        float pitchDueToPosition = transform.localPosition.y * -positionPitch; // position impacting pitch
        float pitchDueToControlThrow = yThrow * controlPitchFactor; // control impacting pitch
        float pitch = pitchDueToPosition + pitchDueToControlThrow; 

        // the yaw changes based on the position on screen (left/right)
        float yaw = transform.localPosition.x * positionYaw;

        // when we move right/left the z axis, the roll changes
        float roll = xThrow * controlRollFactor;

        transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
    }

This is my code.
I don’t quite understand why we need both player input and the position on screen for the pitch. Can’t we just use pitchDueToControlThrow to control the rotation?

Hi Esther_Kim,

We do not need the localPosition. If you remove the entire code and use the user input only in the Euler method, your spaceship would rotate as well.

Rick’s idea was to emphasise the rotation based on the user input and the local position of the spaceship relative to the camera. It is supposed to be a subtle effect to make the rotation look more exciting. Of course, “more exciting” is a matter of personal preference, so you don’t have to agree with his idea. Just using the user input is fine as well if you prefer that in your game.

To see what happens at runtime, you could log the values into your console. Then compare them to the user input values. You can also comment things out or modify the code to see how the spaceship behaves in your game with a different solution. The goal is to make a nice looking game.

Did this help? :slight_smile:


See also:

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

Privacy & Terms