[Solved :D] Camera auto turns 180° from its init position on Play (Animated GIF Included!)


Exactly as the title says: I set my camera to face a certain direction upon start and it turns (yaw) exactly 180° from that once I press play. In my simple mouselook script, I tried making a Start() function setting these exact initial Euler vector coords for testing, and it would start correctly, then snap the other direction as soon as a frame goes by.

(Animated gif of the issue at the bottom of this post)


This leads me to believe it has something to do with the line in my Rotation Application section of Update (there is no Start now, as that was just for testing; the initial values of this line are not set in the variable declarations; hence why I’ve only included the pertinent Update function):


transform.rotation = Quaternion.Euler(currentPitch, currentYaw, 0);


  /* UPDATE (CALLED ONCE EVERY FRAME) */

    void Update () {


            // Pitch w/ Inversion Code

        if (Input.GetKeyDown("i")){ //If 'i' key is pressed
            inverted = !inverted;   //invert if not inverted (default), and vice-versa
        }


            if (inverted)
            {
                targetPitchRot += Input.GetAxis("Mouse Y") * lookSens; //inverted
            }
            else
            {
                targetPitchRot -= Input.GetAxis("Mouse Y") * lookSens; //not inverted
            }

        
            
            
            // Yaw

        targetYawRot += Input.GetAxis("Mouse X") * lookSens;





            // Smoothing

        currentPitch = Mathf.SmoothDamp(currentPitch, targetPitchRot, ref lookSmoothXVel, lookSmoothDamp);
        currentYaw = Mathf.SmoothDamp(currentYaw, targetYawRot, ref lookSmoothYVel, lookSmoothDamp);





            // Rotation Application        

        transform.rotation = Quaternion.Euler(currentPitch, currentYaw, 0);
        




    }           /* ENDUPDATE. */

106361-unityissue-pt001.gif


My bad, you have to assign the values to targetPitchRot and targetYawRot too :

void Start()
 {
      currentPitch = targetPitchRot = transform.eulerAngles.x ;
      currentYaw = targetYawRot = transform.eulerAngles.y ;
 }